I am trying to create an application that will programmatically login 10 users using RDP. The purpose is to autologin these users so someone does not have to manually do it. The first server I tested against (Server 2012) worked just fine. However, I tried a Server 2008 R2 and it continues to prompt me for a password. Here is the code.
static void Main(string[] args)
{
var password = ConfigurationManager.AppSettings["Password"];
var machine = ConfigurationManager.AppSettings["MachineName"];
var userNameList = new List<string>(ConfigurationManager.AppSettings["UserName"].Split(new char[] { ';' }));
foreach(string name in userNameList)
{
Process rdpProcess = new Process();
rdpProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\cmdkey.exe");
rdpProcess.StartInfo.Arguments = "/generic:TERMSRV/" + machine + "/user:" + name + " /pass:" + password;
rdpProcess.Start();
rdpProcess.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe");
rdpProcess.StartInfo.Arguments = "/v " + machine;
rdpProcess.Start();
Thread.Sleep(3000);
}
}
I added the sleep as the connections were coming too fast and I was getting "connection is busy" errors.
Can anyone see anything I am doing wrong?
Don't really know why this was the case but my 2008 servers will not work with FQDN. IP works fine though. Whatever..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With