Publish a VMPlayer Virtual Machine as service

by alefesta

I’ve been asked if it was possible to run a VM Player as a service so to start automatically a specific VM when the phisical host bootstrap.

My first concern is “why I should do that when VMware itself clearly states that for this specific need one should use  VMWare Server? ” ,but after a short consideration on the possible answers I came to the conclusion that, beside the common sense (aka use VMware server at least) there could be special cases, like:

  • The physical host where you want to run the VM cannot install VMware Server
  • You need something that could be easily moved/copied on another physical machine without too much effort
  • You have to run a single VM and there is nobody to control its state or to restart the VM in case of need.

So how I may do? VMPlayer is not built to run as a service but I recalled that, on a Windows machine, you may transform any executable in a service with two executable from the resource kit instsrv.exe and srvany.exe so my first attempt was quite easy:

  1. Install the Windows Resource Kit on a windows machine
  2. Copy instsrv and srvany in the windowssystem32 folder or add them to the path
  3. Launch the command to install vmplayer as service:

instsrv VMPlayer “%SYSTEMROOT%System32srvany.exe”

Or as stated in the MS article http://support.microsoft.com/kb/q137890/

  1. At this point I’ve added a couple of registry keys so to start the VM correctly that means :
    1. KEY “AppParameters” and “AppDirectory” in HKLMSYSTEMCurrentControlSetServicesVMPlayer
    2. The path to the VMX of the VM I want to start in AppParameters and the Directory where the VM reside in AppDirectory.

At this point I simply started the service and…NOTHING!  Well the VMPlayer appear in the TaskManager  list and the service was correctly started but the VM not. After a  brief investigation I found out the problem, seems that srvany is not able to launch the vmx since it is not able to launch something that it is not and executable .

I’ve tried two solution:

  • Launch directly the VMX.
  • Launche Vmplayer from command-line in this way : vmplayer  “pathtovmx”

Manually both works correctly but again there is no way to use them “inside” the newly created service, so now what? I found this really well done article, written in 2001  by  “Nishant Sivakumar”,  called “Beginner’s introductory guide to writing, installing, starting, stopping NT services” http://www.codeproject.com/system/serviceskeleton.asp after a deep read of it I’ve started to google around for something more tangible since develop my own service was not my primary intention and found this very well done application “Launch Serv 2.0”  by “Ernesto Villarroel Zapata”  (http://emutastic.emulation64.com/netosoft) .

The whole process is simple or, at least, seems simple, all I have to do was to download Launch Serv, configure the ini file and click on the install.bat, at this point I’ve opened the Task Manager and observed the list of applications but something goes wrong, I may see the vmplayer.exe  and the vmware-vmx.exe and….another vmplayer.exe !!! What the… I tried to stop the service but one of the two vmplayer.exe remains and so the vm. What I found out is that when I start the service  I effectively launched the player but when the parameter launch the vmx it start a second player totally  uncontrolled.

So now? Well Launch Srv may launch any kind of executable so even a  command/bat file  so the idea is “I launch a simple bat that makes nothing” and as parameter I launch the vmx file. The vmx will open the player by itself in a single instance mode and I may so control its behavior through the service.

But what if I stop the service? The VM will be halted ? Again VMPlayer got a lovely setting that suspend the VM if you close the player and so will do if you stop your newly created service.

So the answer is: yes you may run vmplayer as a service but as VMWare state if you can use VMWare Server.