Home > Cloud Computing, vSphere API > 3 Easy Ways Connecting to Your VM in Private Cloud

3 Easy Ways Connecting to Your VM in Private Cloud

February 24th, 2010 Leave a comment Go to comments

Several folks asked me about how to use vSphere(VI) Java API to connect to a VM running on vSphere. The quick answer is vSphere Java API is not designed for this. You will need VMware Remote Console, browser plug-in, remote desktop/VNC, SSH client etc. However, it can help you to get the information required by the console or plug-in. Tal Altman from CISCO suggested that it be a topic for doublecloud.org. Here it is.

There are 3 ways to connect to the VM from your client side outside the vSphere and Web Access which have built-in support for console access.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure

  1. Using VMware Remote Console which is a standalone application
  2. Using browser plug-in to either IE or Firefox (Note: this is NOT supported by VMware. Please don’t call the company tech support for this.)
  3. Using Remote Desktop, VNC or SSH

The first two connect to the ESX host, and work even there is no guest OS installed on the VM. The last one assumes you have guest OS installed, and have IP network and server components in place already.

Note that these 3 ways work for the VMs in the public cloud as well if the related ports are open in your firewall. It is, however, not the case for most enterprises, therefore I particularly say it’s for VMs in private cloud. If you don’t have firewall issue, feel free to give it a try with public cloud as well.

Let’s go over one by one in details and see how vSphere Java API helps.

1. Using VMware Remote Console.

Download it here and install it with the installer.

Type in command as follows:

>vmware-vmrc.exe -h -m “[storage1 (2)] w2k3_ent_sp2/w2k3_ent_sp2.vmx”

Note: There is a space from the data store to the folder name. And if you put -X after the .exe, you will get the console open full screen.

Key in the username and password and see the whole console coming up:

Optionally, you can skip this screen by specifying the username and password in the command line as follows:

>vmware-vmrc.exe -h -u root -p password -m “[storage1 (2)] w2k3_ent_sp2/w2k3_ent_sp2.vmx”

Note: the username and password is of the host instead of the OS running on the VM. As I tried with MKS ticket as username and password, it didn’t work. It would nice if so.

Two interesting observation here:

  • You can open multiple remote consoles concurrently. Whatever you do with one console is reflected in others. It means you can use it as a tool to help other users.
  • While two consoles running on the same machine, resizing one does the same for the other.

Q: How VI Java API can help?

A: It’s very easy to get the path to the vmx file with VI Java API. The path to get it from a VM is: config.files.vmPathName. Optionally, you can call:

String vmxPath = vm.getConfig.getFiles.getVmPathName();

2. Using a Web browser

This one can be a little tricky. Here is key JavaScript and embedded component in HTML page:

function connect()


mks.connect(host, 902, cfgFile, username, password);



<object id=”mks” classid=”CLSID:338095E4-1806-4ba3-AB51-38A3179200E9″ codebase=’plugin/msie/vmware-mks.cab#version=2,1,0,0′ width=”100%” height=”100%”></object>

For older versions of mks, you may need a different CLSID as follows:

<object width=”100%” height=”100%” classid=”CLSID:DC7D77DA-E1AC-4D40-930B-B87B2954E034″ codebase=”vmware-mks.cab#version=2,0,1,0″>

When not sure, open a console in your Web Access, and find a page like in your Internet temporary folder and search the file similar as follows for CLSID string to copy over.

C:\Documents and Settings\sjin\Local Settings\Temporary Internet Files\


The username and password pair in the connect() function is for ESX host. You can use the MKS ticket as the value for both of them.

Two ways to serve the HTML page: either locally or remotely. In the first case, you can generate a page by replacing the host, cfgFile, username, and password with real values.

In the second case, you can generate a page, or have a static page with JavaScript that parses these values from the URL like this:

var host = queryString(“host”);

var ticket = queryString(“ticket”);

var cfgFile = queryString(“cfgFile”);

mks.connect(host, 902, cfgFile, ticket, ticket);

function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;

this.keyValuePairs = new Array();

if(q) {
for(var i=0; i < this.q.split(“&”).length; i++) {
this.keyValuePairs[i] = this.q.split(“&”)[i];

this.getKeyValuePairs = function() { return this.keyValuePairs; }

this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split(“=”)[0] == s)
return this.keyValuePairs[j].split(“=”)[1];
return false;

function queryString(key){
var page = new PageQuery(window.location.search);
return unescape(page.getValue(key));

You can then use the URL like this to connect to the VM:


Q: How VI Java API can help?

A: VI Java API can help to get the ticket, and cfgFile location.

For ticket, just call the

VirtualMachineMksTicket ticket = vm.acquireMksTicket();

String ticketStr = ticket.getTicket();

For the cfgFile, just get vmPathName as described in #1. The vmPathName is a format like

[storage1 (2)] w2k3_ent_sp2/w2k3_ent_sp2.vmx

You want to replace the “[…]” with the “config.datastoreUrl.url

Then you have all the information to come up a URL to be passed in an IE browser.


If you don’t have a Web server, you can replace the function with real value instead of passing them from the URL.

You can remove the following line to avoid the full screen.


3. Using Remote Desktop, VNC, or SSH

If you know the hostname or IP address of a VM, you can connect using Remote Desktop just as would to a physical. If not, you can use the VI Java API to find out the IP address for you.

String ip = vm.getGuest().getIpAddress();

This code assumes your VM has VMware Tools pre-installed. If not, you will get null. As a general guideline, you should install VMware Tools whenever you make a VM template.

Well, what if you don’t have the VMware Tools installed? It takes more efforts. You can get the MAC address first like this:

VirtualDevice[] vds = vm.getConfig().getHardware().getDevice();

From this array of virtual devices, you check the VirtualEthernetCard type and cast it for its property macAddress.

With the MAC address in hand, you can then use ARP or DHCP to map the MAC address to IP address. For example, type in the following commands on Windows gives you the mapping of IP and MAC address:

C:\Program Files\VMware\VMRC>arp -a

Interface: — 0x4

Internet Address      Physical Address      Type         00-0c-29-d2-78-8f     dynamic           00-50-56-b6-1f-ab     dynamic         00-50-56-47-2d-95     dynamic         00-19-e2-9f-5b-f0     dynamic

You need to be in the same subnet to get the mapping.

Once you get the IP address, you can access the remote computer anyway you want. You need the credentials to the guest OS, or VNC server.

More information

Eric Sloof has a great coverage on the MKS here.

  1. Tanuj Khurana
    April 7th, 2010 at 21:04 | #1

    I am a newbie to vmware development but I have the following requirement. I have to create a web application to which clients connect and then each client sees their list of virtual machines. Through the web interface, they issue commands to start/stop etc their virtual machines. This part is OK. The problem is how do the clients get access to the console. Your article talks about it but I am not clear on how to incorporate this in my application.
    Any help will br greatly appreciated.
    Thank You

  2. April 7th, 2010 at 21:57 | #2

    I assume you will create a web application. If so, you can embed the console in your browser which should be pre-installed with VMware remote console plug-in. If you have VMware Web Access run once, you should have that plugin installed already.

  3. Tanuj Khurana
    April 7th, 2010 at 22:20 | #3

    Actually, the clients do not go to the vmware web access page but to our custom web interface page and login. So, all the clients will have to install the vmware remote console plugin in their browsers ?

  4. Prakritish
    August 12th, 2010 at 16:48 | #4

    Hi Steve,

    I would like to use your solution no. 2, but it looks like for the current version of vsphere 4.0 the solution does not work. It would be great if you could give me some pointers on how to make it work.


  5. August 12th, 2010 at 17:09 | #5

    Hi Prakritish,

    The solution #2 is not supported, so try other two if you could. Thanks!


  6. Vytautas
    March 22nd, 2011 at 07:41 | #6

    What do you mean not supported? Any link with details on that?

  7. March 22nd, 2011 at 09:59 | #7

    No it’s not supported. Sorry I don’t have a link on that.


  8. Anand
    January 6th, 2012 at 14:49 | #8

    Hi Steve,

    I got the url to open the vm console directly but here while trying to hit that link , it is taking me to vcenter authentication screen instead of direct vm console [ windows / linux ]….wat needs to be done to override this authentication issue.

  9. January 6th, 2012 at 16:43 | #9

    Can you explain a bit more what you have done? Also what is the URL like?


  10. Kiran
    February 15th, 2012 at 05:10 | #10

    Hi Steve,

    I am using solution one for connecting to vm console through command.I installed VMware Remote Console plugin ,once executing the command like,
    C:\Program Files\Common Files\VMware\VMware Remote Console Plug-in>vmware-vmrc.exe -h -u root -p password -m “[datastore1] Kiran_VM/Kiran_VM.vmx”

    It is opening the VMware remote console with a popup message “Error opening the remote virtual machine \: Missing server name or connection configuration file name.” Here I get the vmx path from api and all other crediantlies are write. Can you explain what is the meaning of that message.

  11. Kiran
    February 15th, 2012 at 07:39 | #11

    Once i remove -m its working fine for me.

  12. February 15th, 2012 at 11:23 | #12

    Thanks for sharing your tip Kiran!

  13. Anand
    February 24th, 2012 at 00:53 | #13

    @Steve Jin

    Hi Steve,

    Sorry for the late response from my end . The issue is like i am able to frame the URL{to open remote console } using UUID and Mor ID as per guidelines from vmware.

    When i try to hit that URL from my browser, it is taking me to a page where i have to enter user credentials for vmware.After successful authentication , the page is getting routed to vm’s remote console.

    I just like to know whether there is any provision to bye pass this authentication mechanism, i meant something like pre-authenticated session.

  14. Anand
    March 29th, 2012 at 02:38 | #14

    Hi Steve,

    Any update on my above query !


  15. March 30th, 2012 at 00:27 | #15

    Hi Anand,

    Sorry for being late to get back to you. Are you using #2, which is not supported? Thanks!


  16. Shalini
    September 18th, 2012 at 00:36 | #16

    Hi Steve,

    I am developing an application which lists the VMs of a user. The user should be able to view the VM console in the browser. Could you please let me know how to do that?


  17. Shalini
    September 18th, 2012 at 00:40 | #17

    I am developing a web application.

  18. September 18th, 2012 at 23:58 | #18

    I think there is a plugin which is used in vCloud and Lab Manager. You can look into it to see how it’s implemented.


  19. Kreifeur
    November 13th, 2012 at 17:07 | #19

    I tried the #1 : VMWare remote console.
    I got a black screen when connecting using C:\Program Files\VMwareVMRC\vmware-vmrc.exe” -h -u root -p root123456 -m “[datastore1] test/test.vmx”.

  20. Vaibhav
    January 23rd, 2013 at 16:00 | #20

    I tried the #1 VMware remote console, gave same input as above, i am getting error “Invalid option: m”

  21. January 23rd, 2013 at 16:07 | #21

    Valibhav, it’s been almost two years. The versions we used may be different. You may want to read the latest manuals/docs. Please let me know if you find anything new.
    Good luck!

  22. kim
    January 25th, 2013 at 00:27 | #22

    how to get performance data of evry entity using vi java?plzz help me…. i want to retrive its data with respect to time

  23. January 25th, 2013 at 15:40 | #23

    There are a couple of samples included in the API source package. Also check out my book.

  24. kim
    January 28th, 2013 at 00:48 | #24

    ok,thx.. Steve

  25. jet
    September 5th, 2014 at 05:17 | #25

    Hi Steve,

    I have a question about VNC connecting to vmware VM.
    When i input the URL{to open remote console } using UUID and Mor ID as per guidelines from vmware.

    it always show me a window which I have to enter user credentials for vmware.

    Do you know how to access vm by VNC without vmware authentication?

    Thank a lot.


  26. September 9th, 2014 at 15:06 | #26

    I don’t think there is a way to bypass as it’s part of needed security.

  27. Enchara
    February 8th, 2016 at 03:52 | #27

    I am in private cloud. And I want to write a script where a private network VM has to ping another private network VM. These VMs are not reachable by vCenter Server.
    How can I do it?

  28. February 8th, 2016 at 12:21 | #28

    Connection to vCenter is not important. If you have router configured correctly between the two private networks, you should be able to ping each other.


  29. Harpreet Singh
    November 5th, 2016 at 03:00 | #29


    I want to integrate the vnc or novnc console in my vmware plugin in PHP.

    I have esxi and vCenter server.

    Please let me know, how i will make the vnc connection by using websocify?

    Is there any link to open the vnc console?

    Harpreet Singh

  30. November 7th, 2016 at 13:50 | #30

    I am sure you can find plenty of links with google or bing. Good luck!

  1. No trackbacks yet.