Run mstsc.exe with specified username and password

前端 未结 7 1829
悲&欢浪女
悲&欢浪女 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:09

    Process rdcProcess = new Process();
    rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\cmdkey.exe");
    rdcProcess.StartInfo.Arguments = "/generic:TERMSRV/192.168.0.217 /user:" + "username" +  " /pass:" + "password";
    rdcProcess.Start();
    
    rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
    rdcProcess.StartInfo.Arguments = "/v " + "192.168.0.217"; // ip or name of computer to connect
    rdcProcess.Start();
    

    The above code initiates a connection with .217 and I am not being prompted to provide a password. Thanks for help.

提交回复
热议问题