📜 ⬆️ ⬇️

Run VMware Player as Windows Service

Do you have a desire to run Vmware as a background process on a Windows computer?
None of the following is endorsed by VMware. This guide only describes my way to using VMware Player.

  1. Create a virtual machine
  2. Install VMware Player
  3. Creating a VMware Player service
  4. Running virtual machines on Windows startup


Translator: The next paragraph was added after questions appeared in the comments about why all this is necessary.
What could be the gain of this method? I did not check it, but I think that the gain in disk space and system resources (the distribution kit of the second server weighs about 600 MB, and the last player weighs more than three times less). Just remember that the server until recently, lagged behind the support of fresh generations of virtual machines.
')


1.1 Creating a virtual machine



Use VMWare products to create virtual machines. I used Workstation version 5.5 because it creates 5th generation virtual machines. If you use another VMware product, make sure that your product will create a virtual machine that is compatible with VMWare Player .

(Translator's note: The easiest way to use is VMWare Server 2.0, which is completely free, along with VMWare Player. But, of course, you can also create a virtual machine on a modern version of Workstation 6.5)

(VMware Player will be used to start the virtual machine (as this is a free product!).
I also run VMware ACE as a service using the same methods as in the case of VMware Player.

The fifth generation of virtual machines allows you to automatically scale the virtual mic's RAM memory taking into account the available physical memory; all you need to do is add a few parameters to the Vmx file.

memsize = "2048"
MemAllowAutoScaleDown = "TRUE"


In this case, VM (virtual machine) will dispose of 2 GB of RAM, if any. On machines with less than 2 GB of RAM, the player will automatically adjust the amount of used, taking into account the available RAM. Memsize 2048 is not the limit. If you have more than 2 GB of memory installed, simply increase this number.
As far as I know, this is an undocumented function. I found this in a vmx file of a single virtual machine supplied by VMware.

1.2 Installing VMware Player



On the machine on which the service will be executed (hereinafter referred to as the “target machine”), install VMware Player. This example uses version 1.0.1. Player cannot coexist with other VMware products on the same computer, so the target machine must be different from the machine when the virtual machine was created.
(Translator's note: I mean a separate installation of the player, if you do not have a Workstation installed, which includes the player. You can also just delete the VMWare Server from the computer after creating the virtual machine)


1.3 Creating VMWare Player Service



Find copies of instsrv.exe and Srvany.exe from the corresponding Windows Resource Kit. For example, I used the Windows 2003 Resource Kit. Copy instsrv.exe and Srvany.exe to% SYSTEMROOT% on the target machine.
Copy the virtual machine files to a directory on the target computer. Not all files are needed, I only copied the files, as shown below.
image

Add fields to the Vmx file so that VMware Player suppressed all “Ok” messages generated by the user interface and did not show the user the interface.

server.vmx
……
hints.hideAll = "TRUE"
msg.noOk = "TRUE"
... ...


The Hints.hideAll parameter was mentioned in the VMware article - At Your Service! in June 2004. The Msg.noOk parameter was found in the VMware forums.
Create the VirtualServer service on the target machine using instsrv.exe.
instsrv VirtualServer "% SYSTEMROOT% \ System32 \ srvany.exe"
Add registry keys for Srvany.exe so that it runs vmplayer.exe with your virtual machine. For a detailed explanation of how to create custom services in Windows, see the Knowledge Base article How to create a custom service.

VirtualServer.reg
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ VirtualServer \ Parameters]
"Application" = "\" C: \\\\ Program Files \\\ VMware \\\\ VMware Player \\\\ vmplayer.exe \ ""
"AppParameters" = "\" C: \\\\ VirtualServer \\\\ server.vmx \ ""
"AppDirectory" = "\" C: \\\\ VirtualServre \\\\\ "" "


To use another Vmware product, such as ACE, change the value of the “Application” key.
To use another virtual machine, change the value of “AppParameters”.

Create a virtual machine startup batch file called start-vm.bat. This script first checks if the virtual machine files are installed and that the service is not running. It then kills all old VMware processes and eliminates various state files since the last virtual machine startup. At the end, the virtual machine service starts.

::
:: start-vm.bat
::
:: If it doesn't start it
if not exist C: \ VirtualServer goto noServer
:: If the service is already running, then skip starting it
net start | grep -q -i "VirtualServer"
if% ERRORLEVEL% == 0 goto noServer
:: To make sure that the process is dead
taskkill / F / IM vmplayer.exe
taskkill / F / IM vmware-vmx.exe
:: Remove * .lck, * .vmss from the grid directory
del "C: \ VirtualServer \ *. lck"
del "C: \ VirtualServer \ *. vmss"
del "C: \ VirtualServer \ *. vmem"
:: Start the server service
net start VirtualServer
: noServer


Create a batch file to stop the virtual machine called stop-vm.bat. The virtual service stop script kills any VMware processes associated with the running virtual machine.

::
:: stop-vm.bat
::
:: If it doesn't start it
if not exist C: \ VirtualServer goto noServer
:: Start the service
net stop VirtualServer
:: Force kill the processes
taskkill / F / IM vmplayer.exe
taskkill / F / IM vmware-vmx.exe
: noServer


Important: the virtual machine should be in normal after hard closing. Destroying the virtual machine process is the same as if you pulled the power cord out of a socket on a physical computer. If the state of the virtual machine does not matter, then you can use the nonpersistent disk function. Since the disk contents do not change while the virtual machine is running, this termination of the process will not affect the state of the virtual disk.

1.4 Starting Virtual Machines at Windows Startup



Place the startup script in% SYSTEMROOT% \ System32 \ GroupPolicy \ Machine \ Scripts \ Startup. For this example, the startup script is the start-vm.bat file.

image

On the target machine, make start-vm.bat start at system start-up by adding it to the autorun list of group policy. gpedit.msc is a group policy editor. Run the gpedit.msc command to open the Group Policy Editor (Translator’s Note: Start - Run menu) ..


image

In the "Scripts (Startup / Shutdown)" section of the Group Policy Editor, open the Startup Properties window. Click the "Add" button and enter the name of the virtual machine launch script.

image

Perform steps 1-3 for Group Policy Shutdown, but use stop-vm.bat as the completion script. Adding a Shutdown group policy is not strictly required, but it may be important to start stop-vm.bat if it contains more commands than just completing the virtual machine process.
Everything. Use.

Source: https://habr.com/ru/post/48960/


All Articles