Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically login 10 users to remote desktop session

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?

like image 529
maltman Avatar asked Dec 04 '25 04:12

maltman


1 Answers

Don't really know why this was the case but my 2008 servers will not work with FQDN. IP works fine though. Whatever..

like image 149
maltman Avatar answered Dec 06 '25 17:12

maltman