Krzysiek Krzysiek - 1 year ago 214
C# Question

Run mstsc.exe with specified username and password

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 manually in the code? Store them in a temp .rdp file?

Answer Source
Process rdcProcess = new Process();
rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\cmdkey.exe");
rdcProcess.StartInfo.Arguments = "/generic:TERMSRV/ /user:" + "username" +  " /pass:" + "password";

rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
rdcProcess.StartInfo.Arguments = "/v " + ""; // ip or name of computer to connect

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download