Launching VMware remote console from a batch script

For a long time I’ve used this method to deal with starting and stopping the VMware Server 2 services on-demand. My habit was to log into Web Access, start/resume the guest, and launch the Remote Console from there. I recently started using VM shortcuts to launch the Remote Console directly, instead of logging into the VMI Web Access client first. When I’m not making configuation changes, the shortcuts get me to the VM desktop quicker. Naturally, once I saw how simple the shortcut syntax is, I wanted to streamline everything with a script to manage the services the same way I do with the Web Access, and cut out the Web Access piece completely.

The command to launch the Remote Console looks like this.
Linux:
vmware-vmrc -h [<hostname>] [-u <username> -p <password>] [-M <moid> | <datastore path>]

Windows:
vmware-vmrc.exe -h <hostname> [-u <username> -p <password>] -M <moid> | <datastore path>

The user/pass combo is optional. If it’s not passed from the command line you’ll be prompted each time.

You can identify the VM either by the Managed Object ID (MOID) or datastore path, you don’t need both. As I mentioned in that previous post, I can’t get the user/pass to work from the command line unless I use the datastore path. I saw some mention in the forums this might be caused by these guests having been created by the 1.x Server version. Try the MOID and see if it works for you.

You’ll need two bits of info to modify my script to work for you: the path to vmware-vmrc.exe and either the MOID or datastore location.

  • vmware-vmrc.exe: Create a shortcut using the Generate Virtual Machine Shortcut command, then look at the Properties for the shortcut. This is an easy way to confirm the path to vmware-vmrc.exe and find the MOID. You can chuck this shortcut after copying the path.
  • MOID: You can also find the MOID for a VM by looking at vmInventory.xml in /etc/vmware/hostd/ under Linux or %ALLUSERSPROFILE%\Application Data\VMware\VMware Server\hostd under Windows.
  • Datastore path: In the VMware Infrastructure Web Access client, select the VM and click Configure VM. On the General tab, the datastore path will look something like this:
    [standard] <folder>/<name>.vmx

    datastore

Optional

I added a special user to my system and use that user/pass combo on the command line. You don’t have to do this. You can either omit the -u and -p switches from the command line (and enter them at the prompt each time) or use the existing user/pass on the command line. This assumes you’ve been logging into the web client successfully.

I chose to do it this way because I wanted the ease and speed of passing credentials on the command line but did not want to expose my normal account’s password in plaintext.

Add a non-priveleged user to the windows system. This is a Home Premium workstation so I have to make do with the simplified user management and have not added it to a group.
Add that user as an Administrator in VMware:

  1. Select the host object | Permissions tab
  2. Select the User
  3. Change the Role to Administrator
  4. datastore

It makes sense that some reduced permissions level would allow you to launch the remote console but I haven’t experimented yet.

Once you make sure you can log into VMI Web Access with this account, put your info in the script and give it a spin.

My habit, when I’m done with a vm, is to select VMware Remote Console | Troubleshoot | Suspend and Exit (or Power Off and Exit). This tells the vm what to do and exits the console in one step. (Once the console exits, the rest of the script gets evaluated.)

I’ve had no problems using these scripts on the two main systems I work with, both running VMware Server 2.0.2:

  • Win7 Home Prem SP1 x64
  • WinXP Pro SP3 x86

Special bonus, no charge – I added a quick test to the end of the script that simply leaves the VMware server services running if there was more than one guest VM running. This way the services only get stopped when they’re not needed. Be aware it’s not yet smart enough to know if the web client is running.

vmware_merlin.bat

@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  ( 
    REM ** Tomcat is running, just get on with it.
    echo Tomcat is running, getting 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 ** Let's wait a couple--ok, alot--of jiffys to let Tomcat get ready
		REM ** x * 1000 is Number of miliseconds to wait
		> "%Temp%.\sleep.vbs" ECHO WScript.Sleep 2 * 1000
		CSCRIPT //NoLogo "%Temp%.\sleep.vbs"
		DEL "%Temp%.\sleep.vbs"  
		)

REM **** Start Remote Console ****
REM ** This passes the username/password of a user with login permission in VMI and calls
REM ** the guest by the datastore path. I couldn't get the user/pass to work when calling
REM ** the guest by the Managed Object ID.

"C:\Program Files (x86)\Common Files\VMware\VMware Remote Console Plug-in\vmware-vmrc.exe" -u vm -p test1234 -h zaphod:8333 "[standard] merlin/merlin.vmx"

REM **** Check if any guests are running. If so, leave the VMware server services alone. Otherwise,
REM ** stop them.
tasklist /FI "IMAGENAME eq vmware-vmx.exe" 2>NUL | find /I /N "vmware-vmx.exe">NUL
if %ERRORLEVEL%  equ 0  ( 
	REM ** Leave VMware services running and exit **
	echo Another guest is running 
	) else (  
		REM ** Stop VMware services **
		net stop VMwareHostd
		net stop vmauthdservice
		net stop vmnetdhcp
		net stop "vmware nat service"
		net stop VMwareServerWebAccess  
		)

As with the Server script, I call it through this snippet to get rid of the command window.

vmware_merlin_launch.js

var WindowStyle_Hidden = 0
var objShell = WScript.CreateObject("WScript.Shell")
var result = objShell.Run("cmd.exe /c vmware_merlin.bat", WindowStyle_Hidden)

36 mile ride

It was nice to be out of the basement again and off the trainer. I sure do miss the nice warm weather of my last ride, though. I’m so easily tempted into believing I can ride in shorts and T-shirt already!

Even with full gloves, jacket, tights, and skullcap it was a great ride. That clear and calm that makes riding anywhere, anytime a joy. I saw about a half-dozen other cyclists and it was a nice reminder that other people enjoy this too.

I really like this route, the roads are smooth and low-volume. I’m adding this one to my short-list.

Come on summer!

34 mile evening ride

With the time change I’m finally able to ride in the evenings after work. And with the warm temperatures today it was too much to pass up.

I planned to go out for about an hour and ended up riding twice that. I finally got a chance to go south on Sands Rd and see what’s down there. It’s a great ride and I want to explore more.

On top of that I felt really good and hammered, or as close as I get to hammering, the last 20 minutes of the ride to keep the average above 17mph. I think the running is really helping my overall fitness and endurance, which is nice. I’ll never be fast but I love seeing improvement!

As Fat Cyclist commented recently, it was oddly distracting seeing my lily-white knees flashing into my peripheral vision the whole ride. Come on summer!

Easy 20 mile spin

As much as I am stuck being a mediocre endurance athlete (not that I’m complaining…just stating I’m neither fast nor strong) I often find it hard to just go out easy and enjoy the scenery. If my mind wanders, I tend to speed up, push harder, and usually not notice until I’m in the redzone.

So today my minor victory was just making the whole ride easy. I stayed in zone 2 except for a few brief forays in z3 and never pushed into zone 4, geared way down on hills, and generally took in the sights. It was really great to be outside on the bike again. The trainer is a great way to maintain winter fitness but it doesn’t do much for the soul. (In fact, due to recent improvements to the “distraction center”, I’m sure it actively rots my brain.) It was a wholly satisfying ride, especially after my wholly unsatisfying ride two days ago.

Yay me for going slow. My life is so hard.

Foot update

The foot is still painful and I haven’t run on it since the 16 miler. From friends’ descriptions it doesn’t sound like textbook plantar fasciitis and I’ve never had a stress fracture so I don’t know what it feels like. For the time being I’m not running on it and planning to see someone about it this week.

The pain is sharp but only when I roll forward on the ball of my foot. It does affect my walking gait and it would be too painful to run on. So far biking and swimming don’t bother it, so I can keep occupied.

I’m really bummed. Since this is such a critical period for my marathon on April 9th, it’s looking very unlikely right now.

Ugly, ugly 12 mile test ride

What could be more pleasant to look forward to on a fine spring’s Friday evening at the end of the workweek than a chance to get out on the bike? Especially the first outside ride in two months. Not much! Well, maybe a Friday evening’s ride before a two-week vacation? Anyway, suffice it to say I was looking forward to it.

Unfortunately, it was not a great ride and left me in a surprisingly sour mood. It’s not often being active outside, especially on the bike, leaves me anything but refreshed and bright.

It wasn’t anything I can point to; I didn’t even get honked at or flipped off. It just felt bad. Awkward. Alien. As real cyclists refer to bad rides or tired legs as “pedaling squares”, I was pedaling triangles or pentagons…whichever is worse. I felt so un-powerful that any effort at all was uncomfortable. Add that to a general feeling of wanting to get off the bike and I was at a loss to understand my problem, let alone fix it.

So I soft-pedaled home and had dinner and a glass of red wine with my wife. Problem solved!

16 mile run with Tim&Mackenzie

Out and back on the trusty Baltimore & Annapolis Trail. We seriously shoe-horned this run into everyone’s busy schedules.

We finally started about 6pm Sunday night, knowing it would be close to three hours to finish. Another reason the B&A is an easy choice: easy to run in the dark. I don’t really know how risky the neighborhoods are as you get closer to the mall and airport but we figured three able bodies made for an inopportune target. We definitely had the trail to ourselves!

This was my second 16 mile run and worlds, galaxies even, better than the first. The first was solo and easily the worst, hardest, and possibly most satisfying run I’ve ever done.

I was spent at the end but not feeling bad. The bad news is a pain in my left foot, which I now know was there after last week’s 13 miles, got slowly worse over the course of the run. The day after last week’s run I felt it but it wasn’t painful, didn’t last long, and was then barely noticeable so I didn’t think anything of it. Now I know it’s something more. It was bordering on pain by the end of the run and the next morning it was a sharp stab when I rolled over the ball of my foot. It’s less painful today but definitely affects even my walking gait so I’m probably going to skip the mid-week runs and see what happens.

Worst. Post-run. Pic. Ever.

13 mile run with Tim

We ran the Naval Academy grounds, over the Academy bridge, out to Greenbury Point and back, adding a little bit around downtown Annapolis at the end.

Can you say downpour? We were supposed to run 16 today but I wasn’t up for it. I’m glad I’m such a non-endurance athlete: the storm was a little later than forecast but we got a good soaking out of it. It rained the whole time but at least it wasn’t freezing. I was in shorts and a windbreaker and only felt chilled for the 15 minutes we were exposed to the bay breeze on the east side of Greenbury.

Otherwise it was a serviceable run and we both had a good time.

Mackenzie is taking the week off to make sure some hip pain is not serious. She’s seriously active, even for a fifteen year old. She’ll often do our long runs with us midday and then go to swim practice for an hour. Yikes.

New shoes feel good. The old pair was definitely a half-size too small.

Start and stop VMware Server 2 services automatically

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.

vmware2.bat

@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

vmware2_launch.js

var WindowStyle_Hidden = 0
var objShell = WScript.CreateObject("WScript.Shell")
var result = objShell.Run("cmd.exe /c vmware2.bat", WindowStyle_Hidden)

13 mile run with T&M

This was a good run. We used the B&A again because it’s brainless; easy to plan, easy to execute. And it was fast! I’m sure this is the fastest long run I’ve managed. 9:37/mile! Yeehaa. I was feeling pressed the last two miles but it was completely manageable.

The fuelbelt is working well. I’m satisfied with the Hammer HEED and Perpetuem combo. It only has three bottles totalling 21 ounces though, so I think I’m a little behind the overall hydration curve. Have to work on that. Self-supported long runs will require some planning. I’m sure the marathon will have plenty of liquids on-course so no worries there.

The pictures were challenging, and fortunately comical, this time so I’m posting them all. (At least we enjoy it.)

Whoa. Let's try again without the acid.

Mackenzie going with the blinky look

Eyes wide open. And did my arm get longer?