continuous-integrationvix

Unable to use VIX api to power on VM, install software with msiexec, then create snapshot


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:

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:

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"

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