我正在尝试从 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();
}
}
任何想法将不胜感激!