HRESULT
UnregisterVM([in] BSTR vmxFilePath,
[in] ICallback* jobDoneCallback,
[out,retval] IJob** unregisterJob);
This method removes a virtual machine from the host's inventory.
VBScript:
Dim lib
Dim err
Dim job
Dim host
Dim results
Set lib = CreateObject("VixCOM.VixLib")
Set results = Nothing
Set job = lib.Connect(VixCOM.Constants.VIX_API_VERSION, VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_VI_SERVER, "https://viserver/sdk", 0, "Administrator", "administratorpasswd", 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
Set host = results(0)
Set job = Nothing
Set job = host.UnregisterVM("[standard] Windows XP\Windows XP.vmx", Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
' Handle the error...
End If
Set job = Nothing
C#:
class Program
{
static void Main(string[] args)
{
VixCOM.VixLibClass lib = new VixCOM.VixLibClass();
UInt64 err;
object results = null;
VixCOM.IJob job = lib.Connect(VixCOM.Constants.VIX_API_VERSION,
VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_VI_SERVER,
"https://viserver/sdk",
0,
"Administrator",
"administratorpasswd",
0,
null,
null);
err = job.Wait(new int[] { VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE },
ref results);
if (lib.ErrorIndicatesFailure(err)) {
// Handle the error...
}
VixCOM.IHost host = (VixCOM.IHost)((object[])results)[0];
CloseVixObject(job);
job = host.UnregisterVM("[standard] Windows XP\\Windows XP.vmx", null);
job.WaitWithoutResults();
CloseVixObject(job);
host.Disconnect();
}
static void CloseVixObject(Object vixObject)
{
try
{
((IVixHandle2)vixObject).Close();
}
catch(Exception)
{
//Close is not supported in this version of Vix COM - Ignore
}
}
}