您的位置:首页 > 其它

Common Tasks :Getting a Handle to a Virtual Machine

2012-10-19 11:21 288 查看


Getting a Handle to a Virtual Machine

Most virtual machine operations require a handle to identify the virtual machine. The VixVM_Open() function converts
a path name to a handle, which you can use in subsequent function calls. VixVM_Open() is an asynchronous function, so the function call must be completed with a callback function or a call to VixJob_Wait().

To get a handle to a virtual machine

Supply a handle to the host on which the virtual machine is located. See Connecting
to a Host.

On VMware Server only, ensure that the virtual machine is registered on the host. See Registering
and Unregistering Virtual Machines.

Use the host handle and the virtual machine's path name in the host's file system to open the virtual machine withVixVM_Open().

Retrieve the virtual machine handle from the job object.

Example 3-6.

C code below. Click here for Perl. Click
here for COM.
VixHandle jobHandle = VIX_INVALID_HANDLE;
VixHandle vmHandle = VIX_INVALID_HANDLE;
char vmxFilePath[] = "c:\\Virtual Machines\\vm1\\win2000.vmx";
VixError err;
 
// Open virtual machine and get a handle.
jobHandle = VixVM_Open(hostHandle,
vmxFilePath,
NULL, // callbackProc
NULL); // clientData
err = VixJob_Wait(jobHandle,
VIX_PROPERTY_JOB_RESULT_HANDLE,
&vmHandle,
VIX_PROPERTY_NONE);
if (VIX_OK != err) {
// Handle the error...
goto abort;
}
 
Vix_ReleaseHandle(jobHandle);
jobHandle = VIX_INVALID_HANDLE;
// ...Use vmHandle in subsequent code...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息