Name

ReadVariable

Description

HRESULT
ReadVariable([in] LONG variableType,
             [in] BSTR name,
             [in] LONG options,
             [in] ICallback* jobDoneCallback,
             [out,retval] IJob** readJob);

This function reads variables from the virtual machine state. This includes the virtual machine configuration, environment variables in the guest, and VMware "Guest Variables".

Parameters

variableType
The type of variable to read. The currently supported values are:
name
The name of the variable.
options
must be 0.
jobDoneCallback
An ICallback instance that will be called when the operation is complete.
readJob
Returns an IJob object that describes the state of this asynchronous operation.

Return Value

HRESULT

Remarks

Side Effects

None.

Requirements

VixCOM.h, since VMware Workstation 6.0

Example

This example writes and reads a variable you may define, called "myTestVariable".
Dim lib
Dim host
Dim job
Dim vm
Dim results

Set lib = CreateObject("VixCOM.VixLib")

Set job = lib.Connect(VixCOM.Constants.VIX_API_VERSION, VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_WORKSTATION, Empty, 0, Empty, Empty, 0, Nothing, Nothing)

' results needs to be initialized before it's used, even if it's just going to be overwritten.
Set results = Nothing

err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
   WScript.Echo("Error: " & lib.GetErrorText(err, empty))
   WScript.Quit
End If

Set host = results(0)

Set job = host.OpenVM("c:\Virtual Machines\vm1\win2000.vmx", Nothing)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
   WScript.Echo("Error: " & lib.GetErrorText(err, empty))
   WScript.Quit
End If

Set vm = results(0)

Set job = vm.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_LAUNCH_GUI, Nothing, Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
   WScript.Echo("Error: " & lib.GetErrorText(err, empty))
   WScript.Quit
End If

' Wait until VMware Tools are running within the guest, with a 300 second timeout.
Set job = vm.WaitForToolsInGuest(300, Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If

Set job = vm.WriteVariable(VixCOM.Constants.VIX_VM_GUEST_VARIABLE, "myTestVariable", "newValue", 0, Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If

Dim variableVal

Set job = vm.ReadVariable(VixCOM.Constants.VIX_VM_GUEST_VARIABLE, "myTestVariable", 0, Nothing)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_VM_VARIABLE_STRING), results)
If lib.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If
variableVal = results(0)

Set results = Nothing
Set job = Nothing
Set vm = Nothing

host.Disconnect()

Copyright (C) 2007-2010 VMware, Inc. All rights reserved.