($err, $value) = VMReadVariable($vmHandle, $variableType, $name, $options);
This function reads variables from the virtual machine state. This includes the virtual machine configuration, environment variables in the guest, and VMware "Guest Variables".
$value. The value of the variable.
use VMware::Vix::Simple; use VMware::Vix::API::Constants;since Workstation 6.0
my $err = VIX_OK; my $hostHandle = VIX_INVALID_HANDLE; my $vmHandle = VIX_INVALID_HANDLE; my $readValue = NULL; ($err, $hostHandle) = HostConnect(VIX_API_VERSION, VIX_SERVICEPROVIDER_VMWARE_WORKSTATION, undef, # hostName 0, # hostPort undef, # userName undef, # password 0, # options VIX_INVALID_HANDLE); # propertyListHandle die "HostConnect() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK; ($err, $vmHandle) = VMOpen($hostHandle, "c:\\Virtual Machines\\vm1\\win2000.vmx"); die "VMOpen() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK; $err = VMPowerOn($vmHandle, 0, # powerOnOptions VIX_INVALID_HANDLE); # propertyListHandle die "VMPowerOn() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK; $err = VMWaitForToolsInGuest($vmHandle, 300); # timeoutInSeconds die "VMWaitForToolsInGuest() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK; $err = VMWriteVariable($vmHandle, VIX_VM_GUEST_VARIABLE, "myTestVariable", "newValue", 0); # options die "VMWriteVariable() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK; $(err, $readValue) = VixVM_ReadVariable($vmHandle, VIX_VM_GUEST_VARIABLE, "myTestVariable", 0); # options die "VMReadVariable() failed, $err ", GetErrorText($err), "\n" if $err != VIX_OK; ReleaseHandle($vmHandle); HostDisconnect($hostHandle);