3 Easy Ways Connecting to Your VM in Private Cloud

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.

Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.

  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.

This entry was posted in Cloud Computing, vSphere API and tagged , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.


  1. Tanuj Khurana
    Posted April 7, 2010 at 9:04 pm | Permalink

    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. Posted April 7, 2010 at 9:57 pm | Permalink

    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
    Posted April 7, 2010 at 10:20 pm | Permalink

    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
    Posted August 12, 2010 at 4:48 pm | Permalink

    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. Posted August 12, 2010 at 5:09 pm | Permalink

    Hi Prakritish,

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


  6. Vytautas
    Posted March 22, 2011 at 7:41 am | Permalink

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

  7. Posted March 22, 2011 at 9:59 am | Permalink

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


  8. Anand
    Posted January 6, 2012 at 2:49 pm | Permalink

    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. Posted January 6, 2012 at 4:43 pm | Permalink

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


  10. Kiran
    Posted February 15, 2012 at 5:10 am | Permalink

    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
    Posted February 15, 2012 at 7:39 am | Permalink

    Once i remove -m its working fine for me.

  12. Posted February 15, 2012 at 11:23 am | Permalink

    Thanks for sharing your tip Kiran!

  13. Anand
    Posted February 24, 2012 at 12:53 am | Permalink

    @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
    Posted March 29, 2012 at 2:38 am | Permalink

    Hi Steve,

    Any update on my above query !


  15. Posted March 30, 2012 at 12:27 am | Permalink

    Hi Anand,

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


  16. Shalini
    Posted September 18, 2012 at 12:36 am | Permalink

    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
    Posted September 18, 2012 at 12:40 am | Permalink

    I am developing a web application.

  18. Posted September 18, 2012 at 11:58 pm | Permalink

    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
    Posted November 13, 2012 at 5:07 pm | Permalink

    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
    Posted January 23, 2013 at 4:00 pm | Permalink

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

  21. Posted January 23, 2013 at 4:07 pm | Permalink

    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
    Posted January 25, 2013 at 12:27 am | Permalink

    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. Posted January 25, 2013 at 3:40 pm | Permalink

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

  24. kim
    Posted January 28, 2013 at 12:48 am | Permalink

    ok,thx.. Steve

  25. jet
    Posted September 5, 2014 at 5:17 am | Permalink

    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. Posted September 9, 2014 at 3:06 pm | Permalink

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

  27. Enchara
    Posted February 8, 2016 at 3:52 am | Permalink

    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. Posted February 8, 2016 at 12:21 pm | Permalink

    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.


Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.