VMware Workstation 8 added the ability to auto-start virtual machines in the background. This excellent piece of functionality taken from the server product makes workstation like a mini-VM Server. Except that auto-shutdown has not been provided. This post tell you how to configure auto-start VMs and gives you a Windows Shutdown script that will auto-shutdown any shared vms that are running.

Our $9.99 eBook/eClass Bundle brings you up to speed on all the challenges of supporting applications on 64-bit Windows. Check it out.

How to Setup Auto-Start VMs

For those who are not familiar with ESX administration, there are two tricky aspects to setting up auto-start VMs. First, the auto-start setting is not part of each individual VMs – but rather overall settings for the “Shared VMs” category. If you’re like me you may have gotten into the habit of immediately hiding VMWare Workstation’s left hand pane to enable maximum viewing space. However, the “Library” view on the left is how all shared / auto-start VM options are configured.

Here are the steps to configuring a VM for autostart.

ClickView => Customize => Library – to enable the Library view.

Drag and Drop a VM on to the Shared VMs node or create a VM directly under this node.

Note: All the new goodies for managing shared VMs are accessed by Right-clicking the Shared VMs node.

Right-clickShared VMs and selectManage AutoStart VMs

Check the checkbox for each VM you wish to startup when Windows starts.

Remember: This checkbox does NOT automatically shutdown VMs when the machine is shutdown.

ClickOK

Notice that the Right-click menu on Shared VMs includes two other menu items – “Roles” and “Permissions”. In this walk through you will be coding the username and password of an administrator into the script. If this is a local administrator account on a single machine and the script is stored in the Windows default Shutdown Scripts folder, this may not be a big security risk. If, however, doing this violates your company policy, you can setup a new, local windows id that only has the permissions required to stop and suspend VMs. You can even block it from both interactive logon and accessing the real machine from the network.

VMs Will Not Autostart!

When I first setup a shared VM it would never completely startup – the progress bar would stop just short of the end and the VM would never actually enter the start up phase. After a little research I learned that if you have supplemental network filtering drivers (Winsock drivers) on your system, they may prevent shared VMs from starting all the way up. To troubleshoot and resolve this problem use Sysinternals Autoruns.

Check the list for anything that does not have publisher set to “Microsoft Corporation” or “VMware, Inc.”

Retest starting shared VMs after removing any Winsock Providers not created by either of these two companies.

Customizing CSI-VMWSAutoShutdownGuests.cmd

For this script to work, you must:

Have installed VMWare VIX. This is the API for allowing a command that is run on the host machine to control a guest machine (such as asking the guest to shut itself down). VMWare VIX is installed by default when you install VMware Workstation 8 – so it would only be missing if you “hyper-optimized” the install (if you’re a lean hard disk fanatic – you better double check). Check if the “C:\Program Files\VMware\VMware VIX” folder exists (on x64: “C:\Program Files (x86)\VMware\VMware VIX”)

Have installed the VMTools on the guest – so that it can respond to the VIX API calls to properly shutdown.

Disable IPV6 or hardcode the IPV4 ip address instead of using "localhost". VIX does not appear to work with IPV6 when using the "localhost" reference in the attached script. Simply change it to the to IPV4 address of the computer that is running the script. If this is not acceptable due to the address being DHCP assigned, then you may wish to consider disabling IPV6 which is detailed here: http://windows7themes.net/disable-ipv6-windows-7.html

The script that accompanies this article has several advantages over one that is quickly coded for a specific machine:

It automatically operates only on all, running VMs. (as many as are currently running)

It automatically handles 32 and 64-bit Windows (vmware 32-bit binaries are in a different location on each).

It automatically handles VMX disk locations.

It automatically handles varying host workstation names.

It can log it’s activities to the Windows event log.

Suspend is much faster than stop - especially helpful if a large number of VMs are involved. Even if VMWare ends up providing auto-shut down, if it does not include “suspend” functionality, this script will continue to be quite useful.

The vmrun.exe command line in the script reveals several bits of helpful information for crafting you own vmrun commands that work with VMware Workstation 8 shared VMs:

“-T ws-shared” is how you address Shared VMs on Workstation 8.

“-h localhost” is how you avoid hardcoding the local machine name. It also shows that the https:// syntax is unnecessary when on the local machine.

“-u username –p password” are required even if you are currently logged in as an admin and elevated. The big PLUS to this arrangement is that the shutdown script will still do it’s job when the script is run without elevated admin rights.

The “For /f” loop shows you how to iterate through all currently running VMs and do something with them.

The attached script will need to be customized to be used in your configuration.

Store the script in the default Shutdown script location – since it will have a password (possible admin password) embedded. On Windows 7 the folder is: "%windir%\System32\GroupPolicy\Machine\Scripts\Shutdown"

Set LOCALUSER to an administrator profile or one that you have setup with special VMWare and Windows permissions to enable it to shutdown and suspend VMs.

Set LOCALPWD to the password for the user in LOCALUSER

Set LOGGING to "1" if you wish VM shutdowns to be event logged. The companion script eventlogit.vbs is required if logging is enabled.

Set VMACTION to either "stop" or "suspend". "suspend" will result in quicker shutdown and restart times.