Run mstsc.exe with specified username and password

前端 未结 7 1800
悲&欢浪女
悲&欢浪女 2020-12-04 16:06

I realize that in Windows 7, it is not possible to save different credentials for the same host, but I need some workaround.

Can I provide the username and password

7条回答
  •  庸人自扰
    2020-12-04 16:23

    This is an updated version from Krzysiek's post.

    var rdcProcess = new Process
        {
            StartInfo =
                {
                    FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\cmdkey.exe"),
                    Arguments = String.Format(@"/generic:TERMSRV/{0} /user:{1} /pass:{2}", 
                                fp.ipAddress,
                                (String.IsNullOrEmpty(fp.accountDomain)) ? fp.accountUserName : fp.accountDomain + "\\" + fp.accountUserName,
                                fp.accountPassword),
                                WindowStyle = ProcessWindowStyle.Hidden                                
                }
        };
    rdcProcess.Start();
    rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
    rdcProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    rdcProcess.StartInfo.Arguments = String.Format("/f /v {0}", fp.ipAddress); // ip or name of computer to connect
    rdcProcess.Start();
    

提交回复
热议问题