0

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?

4

1 回答 1

6

VMware API 文档中所述,您需要的功能是VixVM_RunProgramInGuest(),它要求您在来宾操作系统(运行在虚拟机上的操作系统)上使用VixVM_LoginInGuest().

该文档有一个关于如何在来宾操作系统中调用程序的示例;这是一个完整的示例,展示了如何连接到虚拟机服务器、打开定义虚拟机的文件并打开它的电源。基本代码如下;不过,您应该阅读完整的示例。

// 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);

连接虚拟机服务器的部分如下。

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);
于 2012-08-26T16:40:36.593 回答