-1

I am trying to do the following with a VM accessed via RDP:

  1. Launch a command prompt thread.sleep long enough to disconnect RDP session (10 seconds, its ok if its longer)

  2. Sendkeys to command prompt to launch an exe that works in interactive mode. A perfect example would be FTP. If you launch FTP without parameters you get an interactive prompt. Its a long story about security but command line parameters will not work, it need to be interactive.. This process will not run while connected to RDP

I have everything working except for one major problem. Once I disconnect from RDP there is no keyboard for sendkeys to work with. I don't remember the exact error offhand but it was basically 'no keyboard connected'

I had an idea that maybe I could create a virtual keyboard that would still be 'connected' when RDP session ends.

I have verified that processes, even DOS from the command prompt will continue to run after disconnecting RDP. The issue is isolated to sendkeys and the keyboard of a VM when not connected.

I have searched high and low, but this one has me stumped. I understand this is a workaround instead of tackling the problem at the source but I only have this option.

The only other alternative I could think of is if something like worked like SendKeys but will work with no keyboard attached?

edit Just to be a little more clear. I have found many other solutions that would work, but I am left with this only idea.

The rules are:

  1. Nothing can be installed on the VM, such as a 'test automation' tool

  2. Everything has to be built in house from scratch using VS2012 C# .net up to 4.5.

Maybe I can find an open source test automation tool but there is no time allowed to research and convert what seems like a possibly complicated application.

Any ideas are most appreciated.

JoeCM
  • 1
  • 2
  • Seems to me like an [XY problem](http://www.perlmonks.org/?node=xy+problem) – EZI Jan 30 '15 at 19:52
  • Your correct about XY. I just want to save the sidebar and concentrate on the particular problem. If it is even possible to do automation of keystrokes on a VM via C#. To start the process while connected to RDP, disconnect and the process continues. – JoeCM Jan 30 '15 at 19:55

1 Answers1

-1

When you create your Process object set StartInfo appropriately:

var proc = new Process {
    StartInfo = new ProcessStartInfo {
        FileName = "program.exe",
        Arguments = "command line arguments to your executable",
        UseShellExecute = false,
        RedirectStandardOutput = true,
        CreateNoWindow = true
    }
};

then start the process and read from it:

proc.Start();
while (!proc.StandardOutput.EndOfStream) {
    string line = proc.StandardOutput.ReadLine();
    // do something with line
}

Taken from here

To send something you can simply use:

proc.StandardInput.WriteLine("Something");

You can simply check in the while loop for some triggers and then write some data into the stream.

Community
  • 1
  • 1
Simon
  • 1,244
  • 8
  • 21