Name
CreateSnapshot
Description
HRESULT
CreateSnapshot([in] BSTR name,
[in] BSTR description,
[in] LONG options,
[in] IVixHandle* propertyList,
[in] ICallback* jobDoneCallback,
[out,retval] IJob** createJob);
This
method
saves a copy of the virtual machine state as a snapshot object.
The ISnapshot object is returned in the IJob object properties.
Parameters
- name
-
A user-defined name for the snapshot; need not be unique.
- description
-
A user-defined description for the snapshot.
- options
-
Flags to specify how the shapshot should be created. Any
combination of the following or 0:
- VIX_SNAPSHOT_INCLUDE_MEMORY - Captures the full state of a
running virtual machine, including the memory.
- propertyListHandle
-
Must be VIX_INVALID_HANDLE.
- jobDoneCallback
-
An ICallback instance that will be called when the
operation is complete.
- createJob
-
Returns an IJob object that describes the state of this
asynchronous operation.
Return Value
Remarks
- This function creates a child snapshot of the current snapshot.
- VMware Server supports only a single snapshot for each virtual machine.
The following considerations apply to VMware Server:
- If you call this function a second time for the same virtual machine
without first deleting the snapshot, the second call will overwrite
the previous snapshot.
- A virtual machine imported to VMware Server from another VMware product
might have more than one snapshot at the time it is imported.
In that case, you can use this function to add a new snapshot to the
series.
- The 'name' and 'description' parameters can be set but not retrieved
using the VIX API.
- 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.
Side Effects
None.
Requirements
VixCOM.h, since VMware Workstation 6.0
Example
VBScript:
Dim lib
Dim host
Dim job
Dim vm
Dim results
Dim snapshot
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
' Handle the 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_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
' Handle the error...
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
' Handle the error...
End If
Set job = vm.CreateSnapshot("Snapshot 1", "Test Snapshot", VixCOM.Constants.VIX_SNAPSHOT_INCLUDE_MEMORY, Nothing, Nothing)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
' Handle the error...
End If
snapshot = results(0)
' Use snapshot...
host.Disconnect()