0

I got this post at run mstsc.exe but if we supply port number it is not working.

Here is my code with port number change.

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

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

I have here 123 port number supply with server name. If server is supply without port number all good.

Please suggest any workaround for this.

Community
  • 1
  • 1
Pat V
  • 64
  • 4

1 Answers1

0

I tried your code on my machine with Win 8.1 to connect to my office. It's working fine, problem is not in code but in environment.

rdcProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
rdcProcess.StartInfo.Arguments = "/v " + "xxxx.cz:33893"; // ip or name of computer to connect
rdcProcess.Start();
Jaroslav Kubacek
  • 1,387
  • 18
  • 26
  • Thanks for the detail Joroslav, but problem you will face when you do not have any saved connection to your server. On this same computer you have tried, please try to create a new windows user and if you try to run the code it will ask for password even though its already supplied on first block of code. Here if server do not have to supply port number all works perfect and you will not be prompted for password. – Pat V Apr 22 '15 at 19:01