Developing VM-Typer (Part 2)

Last week we starting looking at developing 'VM-Typer' - a .Net application that would allow you to automatically type in text from the host computer to an arbitrary virtual machine. The first thing we had to do was get the application up and running with the right security context and thread apartment model (details here: https://blogs.msdn.com/virtual_pc_guy/archive/2005/05/19/420367.aspx). The next thing we will need to do is to make the actual connection to Virtual Server. If you check the UI:VMTyper UI  

You can see that I have provided two radio buttons to specify whether you connect to a local or remote server - as well as a push button to actually initiate the connection. The code that gets launched once you push the button is something like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Connect to the Virtual Server instance

'If RadioButton2 is checked then we want to connect to a remote server
If RadioButton2.Checked Then
Dim typeVSClass As Type
Dim typeDCOM As Type
Dim objDCOM As Object

typeVSClass = GetType(VMVirtualServerClass)
typeDCOM = Type.GetTypeFromCLSID(typeVSClass.GUID, TextBox1.Text, True)
objDCOM = Activator.CreateInstance(typeDCOM)

virtualServer = CType( _
Marshal.CreateWrapperOfType(objDCOM, typeVSClass), _
VMVirtualServerClass)
Else
'Otherwise we just want to connect to a local server
virtualServer = New VMVirtualServerClass
End If

'Now we disable the combobox, populate its drop down list with the names
'of the virtual machines on the server and then re-enable the combo box
ComboBox1.Enabled = False
ComboBox1.Items.Clear()
For Each vm As VMVirtualMachine In virtualServer.VirtualMachines
ComboBox1.Items.Add(vm.Name)
Next
ComboBox1.Text = ComboBox1.Items(0)
ComboBox1.Enabled = True
End Sub

Once this has been done - everything is now ready for us to select a virtual machine and start working with it. But we will discuss that next week :-)

Cheers,
Ben