0

How can I check that a username and password can be logged in remotely on remote machine using remote desktop API and C# code?

Majid Shamkhani
  • 849
  • 2
  • 8
  • 28
  • You can _check_ that using Active Directory, by checking whether the account you're checking has Remote Desktop privileges. Can you explain yourself a little better and show what you have found? – CodeCaster May 07 '12 at 09:45
  • I'm looking for a method that can pass machine IP, username and password to it and it turned true or false for user privilege. – Majid Shamkhani May 07 '12 at 11:37

2 Answers2

1

I believe that this is what you're looking for:

http://www.codeproject.com/Articles/43705/Remote-Desktop-using-C-NET

t3hn00b
  • 904
  • 5
  • 13
1
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.

If you don't want to keep stored credentials in repository, after this code you can call cmdkey.exe again with arguments

/delete:TERMSRV/192.168.0.217
gunr2171
  • 16,104
  • 25
  • 61
  • 88