Name

Clone

Description

HRESULT
Clone(ISnapshot* snapshot,
      LONG cloneType,
      BSTR destConfigPathName,
      LONG cloneOptions,
      IVixHandle* propertyList,
      ICallback* jobDoneCallback,
      IJob** cloneJob)

Creates a copy of the virtual machine specified by the 'vmHandle' parameter.

Parameters

snapshot
Optional. A snapshot belonging to this virtual machine. If you pass NULL (C++), null (C#), or Nothing (VB), the clone will be based off the current state of the virtual machine. If you pass a valid snapshot object, the clone will be a copy of the state of the virtual machine at the time the snapshot was taken.
cloneType
Must be either VixCOM.Constants.VIX_CLONETYPE_FULL or VixCOM.Constants.VIX_CLONETYPE_LINKED.
destConfigPathName
The path name of the virtual machine configuration file that will be created for the virtual machine clone produced by this operation. This should be a full absolute path name, with directory names delineated according to host system convention: \ for Windows and / for Linux.
options
Must be 0.
propertyListHandle
Must be NULL (C++), null (C#), or Nothing (VB).
jobDoneCallback
An ICallback instance that will be called when the operation is complete.
cloneJob
Returns an IJob object that describes the state of this asynchronous operation.

Return Value

HRESULT

Remarks

Side Effects

If the 'cloneType' parameter is VIX_CLONETYPE_LINKED and the 'snapshotHandle' parameter is VIX_INVALID_HANDLE, then the function will create a snapshot of the current virtual machine state and use that to created the linked clone.

Requirements

VixCOM.h, since VMware Workstation 6.5 (not supported on VMware Server)

Example

VBScript:
Set job = host.OpenVM("c:\Virtual Machines\vm1\ubuntu.vmx", Nothing)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If

vm = results(0)

' Create a clone of this virtual machine.
Set job = vm.Clone(Nothing, VixCOM.Constants.VIX_CLONETYPE_LINKED, _
                   "c:\\Virtual Machines\\vm2\\ubuntuClone.vmx", 0, Nothing, Nothing)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If

cloneVM = results(0)

' You can use the new virtual machine as you would any other virtual machine. 
' For example, to power on the new clone:
cloneVM.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_LAUNCH_GUI, Nothing, Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
   ' Handle the error...
End If

Set results = Nothing
Set job = Nothing

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