Name

Delete

Description

HRESULT
Delete([in] LONG deleteOptions,
       [in] ICallback* jobDoneCallback,
       [out,retval] IJob** deleteJob);

This function permanently deletes a virtual machine from your host system.

Parameters

deleteOptions
For VMware Server 2.0 and ESX, this value must be VIX_VMDELETE_DISK_FILES. For all other versions it can be either 0 or VIX_VMDELETE_DISK_FILES. When option is VIX_VMDELETE_DISK_FILES, deletes all associated files. When option is 0, does not delete *.vmdk virtual disk file(s).
jobDoneCallback
A callback function that will be invoked when the operation is complete.
deleteJob
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

Dim lib
Dim job
Dim err
Dim results
Dim host
Dim vm

Set lib = CreateObject("VixCOM.VixLib")

' Connect to the local installation of Workstation. This also initializes the VIX API.
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

' Wait waits until the job started by an asynchronous function call has finished. It also
' can be used to get various properties from the job. The first argument is an array
' of VIX property IDs that specify the properties requested. When Wait returns, the 
' second argument will be set to an array that holds the values for those properties,
' one for each ID requested.
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

' The job result handle will be first element in the results array.
Set host = results(0)

' Open the virtual machine with the given .vmx file.
Set job = host.OpenVM("C:\VMs\winxpprowithsp2\winxpprowithsp2.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.Delete(VixCOM.Constants.VIX_VMDELETE_DISK_FILES, Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
   WScript.Echo("Error: " & lib.GetErrorText(err, empty))
   WScript.Quit
End If

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

host.Disconnect()

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