I use the free VMware Server for a few test and dev purposes on my laptop, but I don’t have any VMs that run all the time. So of course it annoys me to have the VMware Server services running the rest of the time, just sitting around twiddling their thumbs. I’m absolutely certain it takes some of my system resources for them to shoot virtual spitballs at each other in their boredom.
At first I simply scripted the starting and stopping of those services so I could manage them easily when I wanted to. As is usually my way, what originated as two separate scripts (one of net start commands and one of net stop commands, run manually), eventually morphed into a thing with little bits of logic that controls everything from the start of my server use through to the end.
A mis-named couple points of interest:
- When I added the browser launch statement after starting the services, I found I needed to delay a couple seconds to reliably get the login screen. I’ve only used this script on a couple laptop hosts so try it without this delay on your system, in case it’s something weird with mine.
- The script will sit at the IE launch statement until you close the last instance of the browser. Since I only use IE for the VMware Infrastructure Web Access, and so it’s unlikely there are multiple instances, the logic in the script is simple and reliable. If you use IE for normal browsing you’ll likely need to come up with a cleverer way of telling the script to shove on and stop the services.
- Once this all worked reliably I eventually wished to get rid of the annoying command window that stays open the whole time the script is active. I found, through the wisdom of the internet, the attached .js launch method to solve that.
Now I have a quick launch shortcut pointed at vmware2_launch.js to keep things simple and clean. This works well on the two systems I use, both running VMware Server 2.0.2:
- Win7 Home Prem SP1 x64
- WinXP Pro SP3 x86
Here are the code segments. (I need to find a simpler, less aggravating way to present cleaner code in WordPress posts.)
Edit: updated after installing SyntaxHighlighter Evolved. Very nice.
@echo off REM **** Check if Tomcat is running. If so, assume all VMware server services are running. Otherwise, REM ** start them. tasklist /FI "IMAGENAME eq tomcat6.exe" 2>NUL | find /I /N "tomcat6.exe">NUL if %ERRORLEVEL% equ 0 ( echo Tomcat is running, just get on with it. ) else ( REM **** Start VMware services **** net start VMwareServerWebAccess net start vmauthdservice net start VMwareHostd net start vmnetdhcp net start "vmware nat service" REM echo Let's wait a couple--ok alot--of jiffys to let Tomcat get ready REM x is Number of miliseconds to delay > "%Temp%.\sleep.vbs" ECHO WScript.Sleep 2 * 1000 CSCRIPT //NoLogo "%Temp%.\sleep.vbs" DEL "%Temp%.\sleep.vbs" ) REM **** Start web browser **** REM **Using the <hostname> instead of "127.0.0.1" or "localhost" REM **avoids the annoying certificte warnings "C:\Program Files (x86)\Internet Explorer\iexplore.exe" http://zaphod:8308/ui/# REM ** Stop VMware services ** net stop VMwareHostd net stop vmauthdservice net stop vmnetdhcp net stop "vmware nat service" net stop VMwareServerWebAccess
var WindowStyle_Hidden = 0 var objShell = WScript.CreateObject("WScript.Shell") var result = objShell.Run("cmd.exe /c vmware2.bat", WindowStyle_Hidden)