I am using VMware Workstation 6.5 on Windows Vista x64. I am trying to write some C# code that uses VMware Vix v1.6.1 COM API to get a list of registered virtual machines.
The code I am using is as follows:
using System;
using VixCOM;
namespace ConsoleApplication48
{
internal class Program
{
private static void Main()
{
var lib = new VixLibClass();
object results = null;
var job = lib.Connect(Constants.VIX_API_VERSION, Constants.VIX_SERVICEPROVIDER_VMWARE_WORKSTATION, null, 0,
null, null, 0, null, null);
var err = job.Wait(new[] {Constants.VIX_PROPERTY_JOB_RESULT_HANDLE}, ref results);
if (lib.ErrorIndicatesFailure(err))
Console.WriteLine("Error: " + err);
var host = (IHost)((object[])results)[0];
job = host.FindItems(Constants.VIX_FIND_REGISTERED_VMS, null, -1, new DiscoveryCallback(lib));
job.WaitWithoutResults();
host.Disconnect();
}
}
internal class DiscoveryCallback : ICallback
{
protected VixLibClass lib;
public DiscoveryCallback(VixLibClass lib)
{
this.lib = lib;
}
#region ICallback Members
public void OnVixEvent(IJob job, int eventType, IVixHandle moreEventInfo)
{
// this method is never called
}
#endregion
}
}
I am aware that the COM dll is 32-bit, so I made sure that the test application is compiled as 32-bit. Also I made sure that all VMware services are running.
There are no exceptions thrown, no errors returned (as far as I can see) and no events written into the event log.
Strangely enough the above code works when I try to get a list of running VMs using constant VIX_FIND_RUNNING_VMS.
Any ideas on what might be causing this?
Thanks,
Arnie
Quick update on the situation.
I've had a closer look at the official documentation for the FindItems() method. Constant VIX_FIND_REGISTERED_VMS is not listed as a supported parameter - only constant VIX_FIND_RUNNING_VMS is.
My guess is this means that currently VIX API offers no way to get a list of VMs registered on a VMware Workstation instance.
That also would explain why the vmrun.exe command-line utility offers no way of getting registered VMs.
I guess I'll just have to wait until the next version of the VIX API is released.