This document describes how to build a VB Application that can communicate with Virtual Center 2.0.1. When you have trouble with copying the source code out of the PDF document you can also download the Form1.txt. You can find some additional information about getting properties from an object in a free sample chapter from the โScripting VMware Power Tools: Automating Virtual Infrastructure Administrationโ? book. Here is the link to chapter 3.
On April the 25th I received some additional information from Robert Baumstark and my wife corrected the grammar in the PDF document.
Bellow you can find the email message from Rob with some extra tips about using the VIClient.dll.
Actually I believe the example code you've written in there you have no need at all for VIClient.dll. Of those 3 files, VIClient is written entirely by me, though some parts of it aren't much more than VB ports of some of the C# example code. In that DLL there are functions/objects that would replace most of the code in your sample application. The other 2 DLL's I generated and compiled from the VI SDK .WSDL files. I don't know what redistribution restrictions VMWare would put on those files, though since the entire SDK is free I doubt there are any issues with it.
When you're adding references to the project lower down - you only need to add VimService (and optionally VIClient if you want to make use of my code). Whatever you write only ever talks to VimService.DLL - that DLL talks to the XMLSerializers, but since you don't talk to it directly it isn't needed as a reference.
Since there is NO documentation anywhere about the VIClient.DLL - I'll put a little bit in here. I'm basing this on the version of VIClient that I have here - hopefully it's reasonably close to the version that I distributed with the MAC tool.
First off - You'll want to have an instance of the VIClient object that you keep around for the length of your program - I usually make it a private member of the main form of the project.
To connect to VirtualCenter (or an ESX host), you have 2 options. You can call VIClient.Connect(URL, Username, Password), which takes care of a lot of your example code. Or you can create an instance of VIClient.frmLogin. frmLogin.ShowDialog() will pop up a little box prompting for a host to connect to, and a username/password, and will make the connection when you hit the Connect button. Before calling ShowDialog() though, you need to set the frmLogin.aClient to your instance of VIClient.VIClient - that is the client object that will be used to make the connection.
And the final function in there that's really quite handy -
VIClient.GetDynamicProperty(Object as ManagedObjectReference,
PropertyName as String) as ObjectContent()
You can pass any managed object reference and a property name, and it'll return a collection of the results it found.
So..., some example code. (note: all this written right into the e-mail, I haven't test-compiled this, it may have typo's etc)
To duplicate your example program...
Dim X as New VIClient.VIClient
Dim LogonForm as New VIClient.frmLogin
LogonForm.aClient = X
If X.ShowDialog() = DialogResult.OK Then
MsgBox(X.ServiceContent.about.build)
MsgBox(X.ServiceContent.about.name)
MsgBox(X.ServiceContent.about.osType)
MsgBox(X.ServiceContent.setting.Value)
MsgBox(X.ServiceContent.rootFolder.Value)
End If
X.Disconnect()
And an example of grabbing properties. Lets assume that we have a VIClient named X again (already connected and all that) - and another variable VM, which is a managed object reference to some VM.
MsgBox(X.GetDynamicProperty(VM,"config.hardware.numCPU")(0).propSet(0).val) - gets a single value out of the collection of properties returned.
Dim AllHardware() as ObjectContent, aDevice as VirtualDevice
AllHardware = X.GetDynamicProperty(VM, "config.hardware")
For Each aDevice In CType(AllHardware(0).propSet(0).val,
VirtualHardware).device
MsgBox(aDevice.deviceInfo.label)
Next
Also keep in mind there is little to no error handling in VIClient. If an error does occur, it'll just bubble up to your code.
Rob.