VMware Virtual Machine Startup Shortcuts

I am going to share a VMware tidbit with you, something that some of you may already know, but for those of you that don’t, it might help out a little bit. This is particularly aimed at the VMware Workstation crowd. OK, first let me setup the background here. I have a virtual machine that I use for development all the time. It’s running on my laptop, along with my dev tools. I can open VMware workstation and then select the machine I want and fire it up and then close Workstation (since it is set to keep VM’s running when Workstation closes) and all that, but this is time consuming and somewhat aggravating if I am in a hurry. The point is, I am lazy and nit picky and making all those clicks and waiting for programs to load is tedious, especially when I sometimes do it several times a day.

So, I found a nifty little command in the directory where VMware Workstation is installed called vmrun.exe. This command allows you to manipulate your VM’s on the command line. With it you can start and stop, pause, take snapshots of your VM’s, plus many, many more actions. Look at the bottom of this article for more information, I have included the output of vmrun.exe’s usage text, and there is a bunch of stuff there!

Now, back to the article here and my purpose for writing it, what I wanted was a quick and easy way to fire up or start that virtual machine so I could use it when needed, but not have to go through all of the above mentioned steps and wait times. What I came up with was a quick little batch file that when executed, uses that vmrun.exe command to start my virtual machine, easy as pie.

Literally one click and the rest is history. It still takes a minute or two for the machine to boot (luckily it’s a virtual machine running Linux (Debian), so it boots quickly!). Here is the batch file, it’s not fancy but the big thing to illustrate is the usage of the vmrun.exe command:

@echo off
D:
cd "\vmachines\Dev LAMP Server\"
"C:\Program Files\Vmware7\vmrun.exe" start "Dev LAMP Server.vmx"

The batch file is fairly self explanatory, but let me step through it anyway. Line one just turns off the command prompt/console echo. Line two changes to the D drive where the virtual machines are located. Line three changes the directory to the one specifically for the virtual machine that I want to start. Finally, line four fires up the vmrun.exe command with the start operator, which will then start the virtual machine that is specified right after that. You’ll notice the virtual machine name is in quotes, you have to do that if there are spaces in the name, otherwise it will fail. The same goes for the vmrun.exe command path, if there are spaces (like between program and files), you have to have quotes! There you have it, it’s just that simple! Give it a shot and let me know how it goes for you. Drop a comment if you have any questions. Enjoy!!


vmrum.exe Command Usage Output

vmrun version 7.1.5 build-491717

Usage: vmrun [AUTHENTICATION-FLAGS] COMMAND [PARAMETERS]

AUTHENTICATION-FLAGS
--------------------
These must appear before the command and any command parameters.

   -h   (not needed for Workstation)
   -P   (not needed for Workstation)
   -T  (ws|server|server1|fusion|esx|vc|player)
     for example, use '-T server' for VMware Server 2.0
                  use '-T server1' for VMware Server 1.0
                  use '-T ws' for VMware Workstation
                  use '-T esx' for VMware ESX
                  use '-T vc' for VMware vCenter Server
   -u   (not needed for Workstation)
   -p   (not needed for Workstation)
   -vp 
   -gu 
   -gp 

POWER COMMANDS           PARAMETERS           DESCRIPTION
--------------           ----------           -----------
start                    Path to vmx file     Start a VM or Team
                         [gui|nogui]

stop                     Path to vmx file     Stop a VM or Team
                         [hard|soft]

reset                    Path to vmx file     Reset a VM or Team
                         [hard|soft]

suspend                  Path to vmx file     Suspend a VM or Team
                         [hard|soft]

pause                    Path to vmx file     Pause a VM

unpause                  Path to vmx file     Unpause a VM

SNAPSHOT COMMANDS        PARAMETERS           DESCRIPTION
-----------------        ----------           -----------
listSnapshots            Path to vmx file     List all snapshots 
                         [showTree]           in a VM

snapshot                 Path to vmx file     Create a snapshot 
                         Snapshot name        of a VM

deleteSnapshot           Path to vmx file     Remove a snapshot 
                         Snapshot name        from a VM
                         [andDeleteChildren]

revertToSnapshot         Path to vmx file     Set VM state to a 
                         Snapshot name        snapshot

RECORD/REPLAY COMMANDS   PARAMETERS           DESCRIPTION
----------------------   ----------           -----------
beginRecording           Path to vmx file     Begin recording a VM
                         Snapshot name

endRecording             Path to vmx file     End recording a VM

beginReplay              Path to vmx file     Begin replaying a VM
                         Snapshot name

endReplay                Path to vmx file     End replaying a VM

GUEST OS COMMANDS        PARAMETERS           DESCRIPTION
-----------------        ----------           -----------
runProgramInGuest        Path to vmx file     Run a program in Guest OS
                         [-noWait]
                         [-activeWindow]
                         [-interactive]
                         Complete-Path-To-Program
                         [Program arguments]

fileExistsInGuest        Path to vmx file     Check if a file exists 
                                              in Guest OS
                         Path to file in guest

setSharedFolderState     Path to vmx file     Modify a Host-Guest 
                                              shared folder
                         Share name
                         Host path
                         writable | readonly

addSharedFolder          Path to vmx file     Add a Host-Guest 
                         Share name           shared folder
                         New host path

removeSharedFolder       Path to vmx file     Remove a Host-Guest
                         Share name           shared folder

enableSharedFolders      Path to vmx file     Enable shared folders 
                         [runtime]            in Guest

disableSharedFolders     Path to vmx file     Disable shared folders 
                         [runtime]            in Guest

listProcessesInGuest     Path to vmx file     List running processes 
                                              in Guest OS

killProcessInGuest       Path to vmx file     Kill a process in 
                         process id           Guest OS

runScriptInGuest         Path to vmx file     Run a script in 
                         [-noWait]            Guest OS
                         [-activeWindow]
                         [-interactive]
                         Interpreter path
                         Script text

deleteFileInGuest        Path to vmx file     Delete a file in 
Path in guest                                 Guest OS

createDirectoryInGuest   Path to vmx file     Create a directory in 
Directory path in guest                       Guest OS

deleteDirectoryInGuest   Path to vmx file     Delete a directory in 
Directory path in guest                       Guest OS

listDirectoryInGuest     Path to vmx file     List a directory in 
                         Directory path in    Guest OS
                         guest

CopyFileFromHostToGuest  Path to vmx file     Copy a file from host 
Path on host             Path in guest        OS to guest OS

CopyFileFromGuestToHost  Path to vmx file     Copy a file from guest 
Path in guest            Path on host         OS to host OS

renameFileInGuest        Path to vmx file     Rename a file in Guest
                         Original name        OS
                         New name

captureScreen            Path to vmx file     Capture the screen of 
Path on host                                  the VM to a local file

writeVariable            Path to vmx file     Write a variable in 
                 [runtimeConfig|guestEnv]     the VM state
                         variable name
                         variable value

readVariable             Path to vmx file     Read a variable in 
                 [runtimeConfig|guestEnv]     the VM state
                         variable name

VPROBE COMMANDS          PARAMETERS           DESCRIPTION
---------------          ----------           -----------
vprobeVersion            Path to vmx file     List VP version

vprobeLoad               Path to vmx file     Load VP script
                         'VP script text'

vprobeLoadFile           Path to vmx file     Load VP file
                         Path to VP file

vprobeReset              Path to vmx file     Disable all vprobes

vprobeListProbes         Path to vmx file     List probes

vprobeListGlobals        Path to vmx file     List global variables

GENERAL COMMANDS         PARAMETERS           DESCRIPTION
----------------         ----------           -----------
list                                          List all running VMs

upgradevm                Path to vmx file     Upgrade VM file format,
                                              virtual hw

installTools             Path to vmx file     Install Tools in Guest

register                 Path to vmx file     Register a VM

unregister               Path to vmx file     Unregister a VM

listRegisteredVM                              List registered VMs

deleteVM                 Path to vmx file     Delete a VM

clone                    Path to vmx file     Create a copy of the VM
                         Path to destination  vmx file
                         full|linked
                         [Snapshot name]

Examples:

Starting a virtual machine with Workstation on a Windows host
   vmrun -T ws start "c:\my VMs\myVM.vmx"

Stopping a virtual machine on an ESX host
   vmrun -T esx -h https://myHost.com/sdk -u hostUser 
   -p hostPassword stop "[storage1] vm/myVM.vmx"

Running a program in a virtual machine with Workstation 
on a Windows host 
   with Windows guest vmrun -T ws -gu guestUser 
   -gp guestPassword runProgramInGuest 
   "c:\my VMs\myVM.vmx" "c:\Program Files\myProgram.exe"

Running a program in a virtual machine with Server on 
a Linux host with Linux guest
   vmrun -T server -h https://myHost.com:8333/sdk 
   -u hostUser -p hostPassword -gu guestUser 
   -gp guestPassword runProgramInGuest 
   "[standard] vm/myVM.vmx" /usr/bin/X11/xclock 
   -display :0

Creating a snapshot of a virtual machine with
Workstation on a Windows host
   vmrun -T ws snapshot "c:\my VMs\myVM.vmx" mySnapshot

Reverting to a snapshot with Workstation on a Windows host
   vmrun -T ws revertToSnapshot "c:\my VMs\myVM.vmx" 
   mySnapshot

Deleting a snapshot with Workstation on a Windows host
   vmrun -T ws deleteSnapshot "c:\my VMs\myVM.vmx" 
   mySnapshot

Enabling Shared Folders with Workstation on a Windows host
   vmrun -T ws enableSharedFolders "c:\my VMs\myVM.vmx"

One thought on “VMware Virtual Machine Startup Shortcuts”

  1. I do take into account each of the methods you could have presented on the article. They can be incredibly begging which enables it to undoubtedly do the job. Nonetheless, this articles are extremely limited for basic publishing.

Tell me what you are thinking?