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

发布于 2024-11-18 14:16:35 字数 1392 浏览 2 评论 0原文

我正在尝试从 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();
    }
}

任何想法将不胜感激!

I am trying to open RDP from ASP.NET application.
i created a method to create .rdp file with connection parameters but when tried to run this method i got the following error :

An error occur while loading from c:\temp.rdp

Here's my code:

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

any idea will be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文