So I've been struggling trying to get my development VM started and the Samba share it exports mapped when I boot up. Last time I set this up, I'd just run the VM through vmrun.exe with a shortcut in
Start Menu -> Startup. The problem is that on logon, Windows would attempt to mount the share before the VM was started. Also, I'm not entirely sure what happens to a running VM when you shut down Windows without halting/suspending it first, though it never seemed to be an issue.
The following will start the VM and mount the share in non-persistent mode (won't automatically try and re-mount at logon). It will also remove the mount and suspend the VM on logoff, leading to a faster start-up next time.
Fist create two scripts. I dropped them right in the VM's folder.
@echo off "C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" -T ws -u thomas start "D:\vm\Dev\Dev.vmx" nogui ping 10.0.1.199 -n 1 -w 2000 > NUL net use Y: \\dev\thomas /persistent:no
@echo off net use Y: /delete /Y ping 10.0.1.199 -n 1 -w 2000 > NUL "C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" -T ws -u thomas suspend "D:\vm\Dev\Dev.vmx" soft
In both of the scripts, change the drive letter (
Y:), the share (
\\dev\thomas), the location of the VMX file (
D:\vm\Dev\Dev.vmx) and the username (
thomas). This of course depends on a share exported from the guest, DNS or static networking+hosts file entry and bridged networking in VMware. It also requires the same credentials for your Windows account and the share, if this isn't the case, take a peek at the
net use docs. Here's the
vmrun docs (PDF) as well.
Now to setup these scripts to be run at logon and logoff. We'll do this through Group Policy Editor, as it also allows you to set up logoff scripts. Navigate to:
Start -> Run -> gpedit.msc -> User Configuration -> Scripts (Logon/Logoff). Double click
Add and navigate to where you saved your start script. Do the same for Logoff. This will also work in the
Computer Configuration section, but I haven't found a way to allow one to bring the running VM to the foreground.
Enjoy your automatically started VM and mounted network share every time you logon to your computer.