The project to disconnect all the CD’s from all the VM’s with one click of a button is finished so I thought it’s time for a new project. Let’s build a VDI connection broker with an embedded console for the XP VM’s. The first thing I needed to do is figure out how I could embed a console view into my VB application. After some searching in the VMware forums I ended up with one or two posts that weren’t much of a help. I decided to take a closer look at the console that is used in web access. When you logon to web access and select a VM, you can get a console in your Internet Explorer. Let’s find out what happens in the background. Log on to Web Access : https://vcserver/ui
Tuesday, June 19. 2007
VMware MKS client (step one)
Select a virtual machine and click the console tab. Go to your Temporary Internet Files folder (C:\Documents and Settings\Eric\Local Settings\Temporary Internet Files) and look for a recent file with the name vmTabView[1].htm. Copy the vmTabView[1].htm to your desktop and open it in notepad. Scroll down to the following line :
<object id="mks" classid="CLSID:DC7D77DA-E1AC-4D40-930B-B87B2954E034" codebase='plugin/msie/vmware-mks.cab#version=2,0,1,0' width="100%" height="100%"> </object>
What you see is the link to the ActiveX object we all use when we open a console to a virtual machine. What I did next is search the forums for the CLSID and after a while I found an article about someone who tries to do the same as us. This person added some additional lines he received from VMware.
<script language="Javascript" type="text/javascript">
// hostAddress -> ESX host name (fqdn) or the IP address.
// authdPort -> 902 (please make sure port 902 and 903 are open) .
// vmCfgPath -> The VMX location (for the VM in question) .
// uname -> A valid user name.
// password -> A valid password.
mks.connect(esxserver, 902, /vmfs/volumes/45783090-7ae6a1d6-eaed-001185e85a6b/virtual.vmx, uname, password);
</script>
How do we get all this information and what can we use as username and password ? The answer is : The MOB is your friend. Open an Internet Explorer and go to the MOB https://vcserver/mob. Log on with your Windows credentials and navigate to the following path. RetrieveServiceContent / Invoke Method / rootFolder / childEntity / vmFolder /. Select a VM (not a template) and go to the bottom of the screen where you will find VirtualMachineMksTicket. When you invoke the AcquireMksTicket method you will see all the answers you need.
cfgFile | string | "/vmfs/volumes/455ab25f-5b192a18-8911-0019bb240e8a/ VirtualMachine/VirtualMachine.vmx" |
dynamicProperty | DynamicProperty[] | Unset |
dynamicType | string | Unset |
host | string | "192.168.1.1" |
port | int | 902 |
ticket | string | "52c75705-6cea-4837-4ecb-1120ceda692e" |
The ticket is the username and password for your new webpage it will stay the same until you invoke it again but you can retrieve these values from within your VB code just before you launch your embedded Active X control. Here is our new HTML file.
<object id="mks" classid="CLSID:DC7D77DA-E1AC-4D40-930B-B87B2954E034" codebase='https://vcserver/ui/plugin/msie/vmware-mks.cab#version=2,0,1,0' width="100%" height="100%"> </object>
<script language="Javascript" type="text/javascript">
mks.connect(192.168.1.1, 902, /vmfs/volumes/455ab25f-5b192a18-8911-0019bb240e8a/ VirtualMachine/VirtualMachine.vmx, 52c75705-6cea-4837-4ecb-1120ceda692e, 52c75705-6cea-4837-4ecb-1120ceda692e);
</script>
When you open this page in your Internet Explorer you could assume that you will see the console of your VM but you will end up with a black box. I don’t know why it doesn’t work but maybe you can help me out ?
Update : 21-06-2007
I created a new VB project.
I made a copy of \\vcserver\c$\Program Files\VMware\VMware VirtualCenter
2.0\tomcat\webapps\ui\plugin\msie\vmware-mks.cab and placed the dll and exe file in my
project directory.
I added quickMksAx.dll as a reference to my application and wrote the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim test As New QuickMksAxLib.QuickMksAxCtl
MsgBox(test.Connect("192.168.10.10", 902,
"/vmfs/volumes/45783090-7ae6a1d6-eaed-001185e85a6b/nl-nwg-a57/nl-nwg-a57.vmx",
"528364d0-6146-52fe-144c-085e1f7b4f76", "528364d0-6146-52fe-144c-085e1f7b4f76"))
test.SendCAD()
End Sub
I generated the parameters with the MOB bit I know I can do it with the VB application
itself.
I get a true response back ? The only thing I don?t know is how I can embed the
vmware-remotemks.exe for the actual screen. What I did instead is add a WebBrowser box
with the following URL test.html witch contains
<object id="mks" classid="CLSID:DC7D77DA-E1AC-4D40-930B-B87B2954E034"
codebase='https://vcserver/ui/plugin/msie/vmware-mks.cab#version=2,0,1,0' width="100%"
height="100%"> </object>