The virtual machine configuration information is obtained using functions of the
PHT_VM_CONFIGURATION
object. The functions are prefixed with
PrlVmCfg_
. To use the functions, a handle of type
PHT_VM_CONFIGURATION
must first be obtained from the virtual machine object (a handle of type
PHT_VIRTUAL_MACHINE
) using the
PrlVm_GetConfig
function. The following example shows how to obtain the virtual machine name, guest operating system type and version, RAM size, HDD size, and CPU count. In the example, the
hVm
variable contains the
PHT_VIRTUAL_MACHINE
handle identifying the target virtual machine. For the example on how to obtain the handle, see the
Obtaining the Virtual Machine List
section
.
// Obtain the PHT_VM_CONFIGURATION handle.
PRL_HANDLE hVmCfg = PRL_INVALID_HANDLE;
ret = PrlVm_GetConfig(hVm, &hVmCfg);
// Get the virtual machine name.
PRL_STR szVmName;
PRL_UINT32 nVmNameSize = 0;
// Call once with NULL (PRL_INVALID_HANDLE) to get size of buffer
// to allocate for VM name.
PrlVmCfg_GetName(hVmCfg, PRL_INVALID_HANDLE, &nVmNameSize);
printf("Vm name size: %d\n", nVmNameSize);
// Allocate memory for the VM name.
szVmName = (PRL_STR)malloc(nVmNameSize);
// Get the VM name.
PrlVmCfg_GetName(hVmCfg, szVmName, &nVmNameSize);
printf("Virtual machine name: %s\n", szVmName);
// Free the memory allocated for the VM name.
free(szVmName);
// Get the OS type.
PRL_UINT32 nOsType = 0;
PrlVmCfg_GetOsType(hVmCfg, &nOsType);
printf("OS Type: %.8x\n", nOsType);
// Get the OS version.
PRL_UINT32 nOsVersion = 0;
PrlVmCfg_GetOsVersion(hVmCfg, &nOsVersion);
printf("OS Version: %s\n", PVS_GUEST_TO_STRING(nOsVersion));
// Get RAM size.
PRL_UINT32 nRamSize = 0;
PrlVmCfg_GetRamSize(hVmCfg, &nRamSize);
printf("RAM size: %dMB\n", nRamSize);
// Get default HDD size.
PRL_UINT32 nDefaultHddSize = 0;
PrlVmCfg_GetDefaultHddSize(nOsVersion, &nDefaultHddSize);
printf("Default HDD size: %dMB\n", nDefaultHddSize);
// Get CPU count.
PRL_UINT32 nCpuCount = 0;
PrlVmCfg_GetCpuCount(hVmCfg, &nCpuCount);
printf("Number of CPUs: %d\n", nCpuCount);