-1

I have multiple VMware machines; they're all running Windows server, and I would like to run a program in all these machines, not by copying and double-click executing, but by using some VMware API to do that, just like VirtualBox SDK.

Is there any function in the VMware API that allows me to say to a VMware machine to execute a program?

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
daisy
  • 22,498
  • 29
  • 129
  • 265

1 Answers1

6

As reported in the documentation of the VMware API, the function you need is VixVM_RunProgramInGuest(), which requires you to authenticate on the guest OS (the OS running on the virtual machine) with VixVM_LoginInGuest().

The documentation has an example on how to call a program in the guest OS; it's a complete example that shows how to connect to the virtual machine server, open a file defining a virtual machine, and power it on. The essential code is the following one; you should read the complete example, though.

// Authenticate for guest operations.   
jobHandle = VixVM_LoginInGuest(vmHandle,
  "vixuser", // userName
  "secret",  // password 
  0,         // options
  NULL,      // callbackProc
  NULL       // clientData
); 

err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);    

if (VIX_OK != err) {
  // Handle the error.
  goto abort;
}

Vix_ReleaseHandle(jobHandle);

// Run the target program.  
jobHandle = VixVM_RunProgramInGuest(vmHandle,
  "c:\\myProgram.exe",
  "/flag arg1 arg2",
  0,                  // options
  VIX_INVALID_HANDLE, // propertyListHandle
  NULL,               // callbackProc
  NULL                // clientData
); 

err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);

if (VIX_OK != err) {
  // Handle the error.
  goto abort;
}

Vix_ReleaseHandle(jobHandle);

The part to connect to the virtual machine server is the following one.

jobHandle = VixHost_Connect(VIX_API_VERSION,
  VIX_SERVICEPROVIDER_VMWARE_SERVER,
  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) {
  // Handle the error.
  goto abort;
}

Vix_ReleaseHandle(jobHandle);
apaderno
  • 28,547
  • 16
  • 75
  • 90