virtualMachine.RunProgramInGuest Not working

Nov 18, 2011 at 2:52 PM
Edited Nov 18, 2011 at 3:15 PM


  I am using VMWare workstation 8 and was able to successfully launch , shutdown the guest.

But when i try to open/run a program on guest i have no response. I checked the Task manager if it was opening in the background, but i dont see anything in there also.

Below is the C# code that i am using

 var test = virtualMachine.RunProgramInGuest("C:\\Windows\\System32\\notepad.exe", string.Empty,15);

I am geting operation timedout for the above line of code.

The  i tried by using 1 in the options parameter 

 var test = virtualMachine.RunProgramInGuest("C:\\Windows\\System32\\notepad.exe", string.Empty, 1, 15);

here i dont see any exception but still no response on the Guest.

I am using the VMWareTasks 1.6 beta vesion.



Nov 18, 2011 at 5:02 PM

First, make sure you login first. Then, the execution happens on another session, so most likely you get notepad, but you can't see it. Also I believe it's launched and sits there, which means it will timeout waiting for it to finish.

Nov 18, 2011 at 5:53 PM

Here is the whole function that we have been trying to get working. I am a noob to C#.

As you can see, we have tried multiple strings and combinations or parameters to get this to work.

		string vmReturn = string.Empty;
                using (VMWareVirtualHost virtualHost = new VMWareVirtualHost())
                    using (VMWareVirtualMachine virtualMachine = virtualHost.Open(vmxFilePath))
                        //using(VMWareSnapshot vmSnapShot = virtualMachine.Snapshots.GetCurrentSnapshot())
                        //    vmSnapShot.RevertToSnapshot();
                            virtualMachine.LoginInGuest("UserName", "Password", 15);
                            bool iii = virtualMachine.FileExistsInGuest("C:\\Windows\\System32\\notepad.exe", 20);
                            var tttt = virtualMachine.GetFileInfoInGuest("C:\\Windows\\System32\\notepad.exe", 15);
                            //virtualMachine.RunProgramInGuest("NotePad.exe", @"\\PHRAMCLT-MPA\VendorMedia\EPEC\EPEC_NotePadPlusPlus_5.9.4_B01\Test1.txt");
                            //  VMWareVirtualMachine.Process process = virtualMachine.RunProgramInGuest(@"C:\\Windows\\System32\\cmd.exe", string.Empty, 15);
                            var test = virtualMachine.RunProgramInGuest("C:\\Windows\\System32\\notepad.exe", string.Empty, 1, 15);

                            vmReturn = "Test1";
                        catch (COMException ex)
                            vmReturn = ex.Message;


P.S. I have it working with VMRun.exe and noticed that I had to have two switches (-Interactive, -ActiveWindow) to get this to display in the guest VM.



Nov 18, 2011 at 6:50 PM

You'll have to dig deeper about the whole interactive part, I haven't touched this in a while. It's possible that there's a newer parameter to RunProgramInGuest to make it on session 0.

Dec 25, 2011 at 12:41 AM
Edited Dec 25, 2011 at 12:42 AM

var test = virtualMachine.RunProgramInGuest("C:\\Windows\\System32\\notepad.exe", string.Empty, 1, 15);

You are passing 1 in the "options" parameter.

From the VMWareTasks documentation for the "options" parameter:

From the VIX API documentation:
"For Windows guest operating systems, when running a program with a graphical user interface, you can pass VixCOM.Constants.VIX_RUNPROGRAM_ACTIVATE_WINDOW as the value of the options parameter. This option will ensure that the application's window is visible and not minimized on the guest's screen.  This can be combined with the  VixCOM.Constants.VIX_RUNPROGRAM_RETURN_IMMEDIATELY flag using the bitwise inclusive OR operator (|)."


So in conclusion, you probably also want to pass VIX_RUNPROGRAM_ACTIVATE_WINDOW in the "options" parameter.

Dec 28, 2011 at 6:00 PM
Edited Dec 28, 2011 at 6:11 PM
Thank you for the help. Here is the code that works for me.
					virtualMachine.LoginInGuest(vmGuestUser, pgtCrypto.DecryptStringAES(vmGuestPS, SecretKey), 8, 15);
					var err = virtualMachine.RunProgramInGuest(ProgramExec, ProgramCmdArgs, 2, 600);
					vmReturn = err.ExitCode;

There seems to be a small issue that I am trying to see if I can over come. I have to login manually to the VM before running the code above.
Is there a way for the user to login in the vm with VIXCOM and then run my code to be interactive with the guest VM and does it have to be the vSphere console that it only interacts with?

Dec 28, 2011 at 6:51 PM

Here is a relevant Microsoft support article:

How to turn on automatic logon in Windows XP


"... does it have to be the vSphere console that it only interacts with?"

What else do you expect to interact with?

Dec 28, 2011 at 7:33 PM

I was refering to using RDP utility to view the guest VM. The code above only works when I have logged in via the console not a RDP session.

P.S. Thank you for all your help and quick responses.



Dec 28, 2011 at 9:13 PM

Older OS versions allowed you to run mstsc.exe /console so that you can connect to session 0.

Another work-around is to use session 0 isolation:

sc config UI0Detect start= auto

net start UI0Detect

Feb 13, 2013 at 4:38 PM
I use VMware Workstation 7.1.
My task is to
1) Switch snapshot
2) Launch VM
3) Login in session 0 (I need 0 because i want to launch AutoIt executable script on this VM)
4) Launch AutoIt executable script (it is .exe file)

1 & 2 I know how to do.
My problem is how to Login to session 0 and launch the application in session 0 so I can see it on the screen.
May be I need only to launch the application in session 0.
I used following code on already powered ON and logged in VM.
virtualMachine = virtualHost.Open(path2vm);
virtualMachine.Login(usrTextBox.Text, pswTextBox.Text);
virtualMachine.RunProgramInGuest(@runAppTextBox.Text, string.Empty);
But it launches chosen application in another session so I cannot see it on my screen. I see it in the processes only.
I get Interactive Services Detection message...

In this topic you told about "virtualMachine.LoginInGuest(vmGuestUser, pgtCrypto.DecryptStringAES(vmGuestPS, SecretKey), 8, 15);" but in my environment there is no LoginInGuest. There is Login only and the method doesn't support session parameters.

Please help me how to complete my task?
Feb 13, 2013 at 5:13 PM
This project has moved to Github. Please post questions to!forum/vmwaretasks.
Feb 13, 2013 at 7:11 PM