Question

I am at a loss on how to use the VIX api to install my software under test as part of what hopefully will be an addition to my continuous integration. Here are the operations at a high level:

  1. power on VM snapshot
  2. Install an msi package on the VM using RunProgramInGuest (this msi is my software under test)
  3. shutdown the VM
  4. take snapshot

Now - these steps work fine if I first manually log into an already-powered-on snapshot and just start my program in step 2. Everything just works. However, if I start at step 1 and allow VIX to power on the snapshot, my RunProgramInGuest just doesn't do what it normally would had I been logged in already

In the guest VM, I have:

  • A .bat file on the desktop which calls a Task created through Task Scheduler. This task is set to run with Highest privileges. I am using the ideas from Using VMRUN with Windows Vista and UAC. Although note: I have UAC completely turned off for now so this is not the issue
  • The Task from above will run a different .bat file on the desktop which is my installation script e.g. msiexec /i ...

The code which the host runs which is choking unless I am already logged into the VM:

using (VMWareVirtualHost virtualHost = new VMWareVirtualHost()) {
    virtualHost.ConnectToVMWareWorkstation();

    using (VMWareVirtualMachine virtualMachine = virtualHost.Open(@"D:\VMware-VMs\testvm-W7x86-3\testvm-W7x86-3.vmx"))
    {

        virtualMachine.PowerOn();
            virtualMachine.WaitForToolsInGuest();  
        virtualMachine.LoginInGuest("myusername", "myfakepassword");

        VMWareVirtualMachine.Process guestProcess = virtualMachine.RunProgramInGuest(@"C:\Windows\System32\cmd.exe", @"/c C:\Users\myusername\Desktop\StartTask.bat", Constants.VIX_RUNPROGRAM_ACTIVATE_WINDOW);
        Thread.Sleep(60000);
        virtualMachine.RunProgramInGuest(@"C:\Windows\System32\cmd.exe", @"/c C:\Windows\System32\shutdown.exe -s -t 0");
        Thread.Sleep(30000); //wait for guest to shutdown before continuing to make snapshot..

...and so forth

My questions:

  • Why is it that this is only working when I am already logged into the already powered on VM?
  • Is there another way I should go about doing this, outside of using the VIX api (e.g. such as using Psexec.exe or something similar)? The way this is set up using a Task set to run with Highest privs - this means that any VM I want to bring into the mix must have this Task set up. I have looked at other ways - RemoteInstall looks very promising except you must turn off UAC in order for it to work. So I'm now resorting to these hacky workarounds.

EDIT: The same behavior occurs if I use vmrun.exe to start the task. Unless I am already logged into the machine through a remote session, it doesn't work e.g.:

EDIT: The same behavior occurs if I use sysinternals 'PsExec.exe' to run program in the VM - it only works if I am already logged into an interactive session.

vmrun -T ws -gu myusername -gp myfakepassword runProgramInGuest D:\VMware-VMs\testvm-3\testvm-W7x86-3.vmx -activeWindow "C:\users\myusername\desktop\StartTask.bat"
Was it helpful?

Solution

From the VMvare docs: "VIX_LOGIN_IN_GUEST_REQUIRE_INTERACTIVE_ENVIRONMENT should be used to ensure that the functions CaptureScreenImage, OpenUrlInGuest, and RunProgramInGuest work correctly."

This flag assumes that the VM is already running and you are logged in.

http://www.vmware.com/support/developer/vix-api/vix16_reference/lang/com/functions/LoginInGuest.html

OTHER TIPS

There's a framework that does exactly that and you can freely browse its source code: RemoteInstall

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top