Krzysiek Krzysiek - 2 months ago 40
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?

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.