VMware {code} Community
thinguy3n
Contributor
Contributor

VixVM_RunProgramInGuest doesn't start right after the vmware is powered up

I have a vix program with common tasks including start the vmware, wait for vmware tool, then run a program in guest. The problem that I encounter is that my program in guest never get started right after the vmware is powered up. Vix seems to hang for a while. I usually have to terminate it. The second time when I run the program, it'll start my program in Guest. Is it because Vix doesn't know when Guest is finished loading? Is there a way to put a wait before calling RunProgramInGuest?

Thanks

0 Kudos
6 Replies
admin
Immortal
Immortal

Generally the flow of operations should be as you describe:

1) Power on (or resume) a virtual machine.

2) Call WaitForToolsInGuest on that virtual machine.

3) Use RunProgramInGuest on that virtual machine to start a program.

If WaitForToolsInGuest completes successfully, the virtual machine should be in the correct state to run an application.

Could you give us some more infomation:

  • What version of VIX are you using?
  • What VMware product are using to run the virtual machine? What version of that product?
  • What is the guest OS in the virtual machine?
  • What version of VMware Tools is installed in that virtual machine? You can determine this by starting the VMware Toolbox and clicking on the "About" tab.
    0 Kudos
    thinguy3n
    Contributor
    Contributor

    Hi Matt,

    • What version of VIX are you using? I’m using Vix 1.10.3 build-368992

    • What VMware product are using to run the virtual machine? What version of that product? I’m using Vmware Workstation 6.5.3 build -185404

    • What is the guest OS in the virtual machine? I tried this on fedora, ubuntu, win7, vista basic, winxp and all have the same problem with runProgramInGuest.

    • What version of VMware Tools is installed in that virtual machine? You can determine this by starting the VMware Toolbox and clicking on the "About" tab. The version that I am using is 7.8.6-185404

    Thanks

    Thi

    0 Kudos
    admin
    Immortal
    Immortal

    Hmm. A couple more questions:

    • What kind of application are you running in the guest?
    • What arguments are you passing to RunProgramInGuest()?
    0 Kudos
    thinguy3n
    Contributor
    Contributor

    Hi Matt,

    • What kind of application are you running in the guest? The application is a script ( for linux machines) and exe( which basically is just autoIT script converted into exe). The script does some batch copying and start some other exe.

    • What arguments are you passing to RunProgramInGuest()?I’m passing 2 arguments in a string like this “RC1 A_B”

    • Here is the script in case you need it. It’s just basic script that I got from the API Reference site. Please let me know if you see anything wrong.

    #include "vix.h"

    #define NULL 0

    #include <stdio.h>

    int main(int argc, char * argv[])

    {

    VixError err = VIX_OK;

    VixHandle hostHandle = VIX_INVALID_HANDLE;

    VixHandle jobHandle = VIX_INVALID_HANDLE;

    VixHandle vmHandle = VIX_INVALID_HANDLE;

    char *readValue = NULL;

    jobHandle = VixHost_Connect(VIX_API_VERSION,

    VIX_SERVICEPROVIDER_VMWARE_WORKSTATION,

    NULL, // hostName

    0, // hostPort

    NULL, // userName

    NULL, // password

    0, // options

    VIX_INVALID_HANDLE, // propertyListHandle

    NULL, // callbackProc

    NULL); // clientData

    err = VixJob_Wait(jobHandle,

    VIX_PROPERTY_JOB_RESULT_HANDLE,

    &hostHandle,

    VIX_PROPERTY_NONE);

    if (VIX_OK != err) {

    goto abort;

    }

    Vix_ReleaseHandle(jobHandle);

    jobHandle = VixVM_Open(hostHandle,

    argv[1], //vmx path

    NULL, // callbackProc

    NULL); // clientData

    err = VixJob_Wait(jobHandle,

    VIX_PROPERTY_JOB_RESULT_HANDLE,

    &vmHandle,

    VIX_PROPERTY_NONE);

    if (VIX_OK != err) {

    printf("Error while opening the vmware!: %d\n", err);

    // Handle the error...

    goto abort;

    }

    //printf("Here!\n");

    Vix_ReleaseHandle(jobHandle);

    jobHandle = VixVM_PowerOn(vmHandle,

    VIX_VMPOWEROP_LAUNCH_GUI, // powerOnOptions

    VIX_INVALID_HANDLE, // propertyListHandle

    NULL, // callbackProc

    NULL); // clientData

    err = VixJob_Wait(jobHandle,VIX_PROPERTY_NONE);

    if (VIX_OK != err) {

    printf("Error while powering on the vmware!: %d\n", err);

    goto abort;

    }

    Vix_ReleaseHandle(jobHandle);

    // Wait until guest is completely booted.

    jobHandle = VixVM_WaitForToolsInGuest(vmHandle,

    300, // timeoutInSeconds

    NULL, // callbackProc

    NULL); // clientData

    err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);

    if (VIX_OK != err) {

    // Handle the error...

    goto abort;

    }

    Vix_ReleaseHandle(jobHandle);

    printf("Logging in!\n");

    // Authenticate for guest operations.

    jobHandle = VixVM_LoginInGuest(vmHandle,

    argv[2], // userName

    argv[3], // password

    0, // options

    NULL, // callbackProc

    NULL); // clientData

    err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);

    if (VIX_OK != err) {

    printf("Error logging in!: %d\n", err);

    // Handle the error...

    goto abort;

    }

    printf("Logged in successfully!\n");

    Vix_ReleaseHandle(jobHandle);

    jobHandle = VixVM_WriteVariable(vmHandle,

    VIX_GUEST_ENVIRONMENT_VARIABLE,

    "SQUISH_LICENSEKEY_DIR",

    "C:
    Users
    drevil",

    0, // options

    NULL, // callbackProc

    NULL); // clientData);

    err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);

    if (VIX_OK != err) {

    printf("error setting SQUISH_LICENSEKEY_DIR: %d\n", err);

    goto abort;

    }

    Vix_ReleaseHandle(jobHandle);

    jobHandle = VixVM_ReadVariable(vmHandle,

    VIX_GUEST_ENVIRONMENT_VARIABLE,

    "SQUISH_LICENSEKEY_DIR",

    0, // options

    NULL, // callbackProc

    NULL); // clientData);

    err = VixJob_Wait(jobHandle,

    VIX_PROPERTY_JOB_RESULT_VM_VARIABLE_STRING,

    &readValue,

    VIX_PROPERTY_NONE);

    if (VIX_OK != err) {

    printf("error getting SQUISH_LICENSEKEY_DIR: %d\n", err);

    goto abort;

    }

    printf(readValue);

    Vix_ReleaseHandle(jobHandle);

    jobHandle = VixVM_ReadVariable(vmHandle, VIX_VM_GUEST_VARIABLE, "ip", 0, NULL, NULL);

    err = VixJob_Wait(jobHandle,

    VIX_PROPERTY_JOB_RESULT_VM_VARIABLE_STRING,

    &readValue,

    VIX_PROPERTY_NONE);

    if (VIX_OK != err)

    {

    printf("error getting the ip address: %d\n", err);

    }

    printf(readValue);

    /*jobHandle = VixVM_PowerOff(vmHandle,

    VIX_VMPOWEROP_FROM_GUEST, // powerOffOptions

    NULL, // callbackProc

    NULL); // clientData

    err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);

    if (VIX_OK != err) {

    // Handle the error...

    goto abort;

    }

    printf(readValue);*/

    Vix_ReleaseHandle(jobHandle);

    jobHandle = VIX_INVALID_HANDLE;

    // Run the target program.

    jobHandle = VixVM_RunProgramInGuest(vmHandle,

    argv[4],//program path

    argv[5],//program command line arguments

    0, // options,

    VIX_INVALID_HANDLE, // propertyListHandle,

    NULL, // callbackProc,

    NULL); // clientData

    err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);

    printf("Starting script");

    if (VIX_OK != err) {

    printf("Error starting script: %d\n", err);

    goto abort;

    }

    abort:

    Vix_FreeBuffer(readValue);

    Vix_ReleaseHandle(jobHandle);

    Vix_ReleaseHandle(vmHandle);

    VixHost_Disconnect(hostHandle);

    • }

    Thanks

    Thi

    0 Kudos
    admin
    Immortal
    Immortal

    The code seems fine, so I don't have any answers for you at this point.

    When you say that the call to RunProgramInGuest() hangs, can you look in the virtual machine and see if

    1) There is a process called VMwareService.exe running?

    2) If the application you launched using RunProgramInGuest() is running (in the Task Manager)?

    0 Kudos
    SoMoS
    Contributor
    Contributor

    The call to WaitForToolsInGuest is buggy (as some other of the VIX API methods). You probably want to check http://vmwaretasks.codeplex.com/ as they provide sometimes goof support.

    Goos luck!

    0 Kudos