HRESULT FindItems([in] LONG searchType, [in] IVixHandle* searchCriteria, [in] LONG timeout, [in] ICallback* jobDoneCallback, [out,retval] IJob** findJob);
This method asynchronously finds Vix objects and calls the application's ICallback object's OnVixEvent method to report each object found. For example, when used to find all running virtual machines, FindItems() returns a series of virtual machine file path names.
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_WORKSTATION, null, 0, null, null, 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]; job = host.FindItems(VixCOM.Constants.VIX_FIND_RUNNING_VMS, null, -1, new DiscoveryCallback(lib)); job.WaitWithoutResults(); host.Disconnect(); } class DiscoveryCallback : VixCOM.ICallback { protected VixCOM.VixLibClass lib; public DiscoveryCallback(VixCOM.VixLibClass lib) { this.lib = lib; } public void OnVixEvent(VixCOM.IJob job, int eventType, VixCOM.IVixHandle moreEventInfo) { UInt64 err; // Ignore progress reports. if (eventType != VixCOM.Constants.VIX_EVENTTYPE_FIND_ITEM) { return; } object results = null; err = moreEventInfo.GetProperties(new int[] { VixCOM.Constants.VIX_PROPERTY_FOUND_ITEM_LOCATION }, ref results); if (lib.ErrorIndicatesFailure(err)) { // Handle the error... return; } string vmPathName = (string)((object[])results)[0]; // vmPathName now has the path to the virtual machine's .vmx file. // You can use it to open the virtual machine. } } }