Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从c:\temp.rdp加载时出错_C#_.net_Exception Handling_Rdp - Fatal编程技术网

C# 从c:\temp.rdp加载时出错

C# 从c:\temp.rdp加载时出错,c#,.net,exception-handling,rdp,C#,.net,Exception Handling,Rdp,我正在尝试从ASP.NET应用程序打开RDP。 我创建了一个方法来创建带有连接参数的.rdp文件,但当尝试运行此方法时,出现以下错误: 从c:\temp.rdp加载时出错 这是我的密码: public static void RdcTest(string server, string domain, string username, string password) { string encyptedPassword = ""; //Calling the CryptUnpro

我正在尝试从ASP.NET应用程序打开RDP。 我创建了一个方法来创建带有连接参数的.rdp文件,但当尝试运行此方法时,出现以下错误:

从c:\temp.rdp加载时出错

这是我的密码:

public static void RdcTest(string server, string domain, string username, string password)
{
    string encyptedPassword = "";

    //Calling the CryptUnprotectData API to encypt the password, 
    //Read this link for how to do this:
    //http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic21805.aspx

    string filename = @"c:\temp.rdp";
    if (!File.Exists(filename))
    {
        using (FileStream fs = File.Create(filename))
        using (StreamWriter sw = new StreamWriter(fs))
        {                
            sw.WriteLine("screen mode id:i:2");
            sw.WriteLine("desktopwidth:i:1440");
            sw.WriteLine("desktopheight:i:900");
            sw.WriteLine("full address:s:" + server);
            sw.WriteLine("username:s:" + username);
            sw.WriteLine("domain:s:" + domain);
            sw.WriteLine("password 51:b:" + encyptedPassword);
        }

        Process rdcProcess = new Process();

        string strExE = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
        rdcProcess.StartInfo.FileName = strExE;
        rdcProcess.StartInfo.Arguments = filename;
        rdcProcess.Start();
    }
}

任何想法都将不胜感激

什么样的错误?更具体地说,我首先在控制台应用程序中测试了此方法,但收到消息错误(只是一个窗口消息错误)说“从c:\temp.rdp加载时发生错误”。您确定要这样做吗?即使成功,它也会在服务器上打开mstsc.exe,用户不会看到任何事情发生。我要补充的是,用户不会看到任何事情发生,除非服务器和客户端是同一台机器,这可能适用于开发,但可能不适用于生产,查看>>>我可以从命令行输入smtsc,然后打开一个窗口,这样我可以输入IP和用户名,然后我可以将此文件保存到我的PC,最后我可以单击此文件以运行rdp到目标,那么为什么我不能从代码执行此操作呢????