从c:\ temp.rdp加载时发生错误

时间:2011-07-04 07:24:39

标签: 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 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();
    }
}

任何想法都将不胜感激!

0 个答案:

没有答案