Name
RevertToSnapshot
Description
HRESULT
RevertToSnapshot([in] ISnapshot* snapshot,
[in] LONG options,
[in] IVixHandle* propertyList,
[in] ICallback* jobDoneCallback,
[out,retval] IJob** revertJob);
Restores the virtual machine to the state when the specified snapshot was
created.
Parameters
- snapshot
-
An ISnapshot object representing the snapshot to remove. A virtual machine's snapshots
can be accessed through VM::GetRootSnapshot()
- options
-
Any applicable VixVMPowerOpOptions. If the virtual machine was
powered on when the snapshot was created, then this will determine
how the virtual machine is powered back on. To prevent the virtual
machine from being powered on regardless of the power state when
the snapshot was created, use the
VIX_VMPOWEROP_SUPPRESS_SNAPSHOT_POWERON flag.
VIX_VMPOWEROP_SUPPRESS_SNAPSHOT_POWERON is mutually exclusive to all
other VixVMPowerOpOptions.
- propertyListHandle
-
Must be
NULL (C++), null (C#), or Nothing (VB).
- jobDoneCallback
-
An ICallback instance that will be called when the
operation is complete.
- revertJob
-
Returns an IJob object that describes the state of this asynchronous operation.
Return Value
HRESULT
Remarks
- Restores the virtual machine to the state when the specified snapshot was
created. This function can power on, power off, or suspend a virtual machine.
The resulting power state reflects the power state when the snapshot was
created.
- When you revert a powered on virtual machine and want it to display in the
Workstation user interface,
options must have the VIX_VMPOWEROP_LAUNCH_GUI flag, unless the
VIX_VMPOWEROP_SUPPRESS_SNAPSHOT_POWERON is used.
- The VIX_PROPERTY_VM_TOOLS_STATE property of the virtual machine handle is
undefined after the snapshot is reverted.
- Starting in VMware Workstation 6.5, snapshot operations are allowed on
virtual machines that are part of a team. Previously, this operation failed
with error code VIX_PROPERTY_VM_IN_VMTEAM. Team members snapshot independently
so they can have different and inconsistent snapshot states.
- This function is not supported when using the
VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_PLAYER
host type.
- If the virtual machine is open and powered off in the UI, this function
now closes the virtual machine in the UI before reverting to the snapshot.
To refresh this property, you must wait for tools in the guest.
- After reverting to a snapshot, you must call
VM::WaitForToolsInGuest
before executing guest operations or querying guest properties.
Side Effects
None.
Requirements
VixCOM.h, since VMware Workstation 6.0
Example
This example reverts to the root snapshot belonging to a virtual machine.
Dim lib
Dim host
Dim vm
Dim job
Dim err
Dim results
Dim snapshot
results = Nothing
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)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT), result)
If lib.ErrorIndicatesFailure(err) Then
' Handle error...
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), result)
If lib.ErrorIndicatesFailure(err) Then
' Handle error...
End If
Set vm = results(0)
err = vm.GetRootSnapshot(0, snapshot)
If lib.ErrorIndicatesFailure(err) Then
' Handle error...
End If
Set job = vm.RevertToSnapshot(snapshot, 0, Nothing, Nothing)
err = job.WaitWithoutResults()
Set snapshot = Nothing
Set results = Nothing
Set job = Nothing
Set vm = Nothing
host.Disconnect()