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.
vmware-vmrc -h [<hostname>] [-u <username> -p <password>] [-M <moid> | <datastore path>]
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:
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:
- Select the host object | Permissions tab
- Select the User
- Change the Role to Administrator
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.
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&amp;amp;gt;NUL | find /I /N "tomcat6.exe"&amp;amp;gt;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
&amp;amp;gt; "%Temp%.\sleep.vbs" ECHO WScript.Sleep 2 * 1000
CSCRIPT //NoLogo "%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&amp;amp;gt;NUL | find /I /N "vmware-vmx.exe"&amp;amp;gt;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.
var WindowStyle_Hidden = 0
var objShell = WScript.CreateObject("WScript.Shell")
var result = objShell.Run("cmd.exe /c vmware_merlin.bat", WindowStyle_Hidden)