Managing the Default Virtual Machine Location with Windows Virtual PC

Virtual PC 2004 / 2007 always default to creating new virtual machines in the current users “My Documents” folder.  Users who need to use an alternate location can do so by setting up the MYVIRTUALMACHINES environment variable.

Things have changed significantly with Windows Virtual PC.

The first change is that we no longer look at the MYVIRTUALMACHINES environment variable.

The second change is that we no longer enforce a static default location.  Rather – every time you create a new virtual machine – the location that you specify for the new virtual machine:


Will be used as the default virtual machine location the next time you try to create a virtual machine.

Finally – if you do want to programmatically set a default location you can do so using some simple scripts:


# Check for correct command-line arguments
If ($path -eq “”)
 write-host “Missing command-line argument.”
 write-host “USage: SetDefaultVMPath.ps1 -path `”Default path to use for new virtual machines`“”
# Connect to Virtual PC
$vpc=new-object –com VirtualPC.Application –Strict
# Set the new default VM path
$vpc.DefaultVMConfigurationPath = $path


Option Explicit
Dim namedArguments, vpc, defaultVMPath
‘ Check that the script is running at the command line.
If UCase(Right(Wscript.FullName, 11)) = “WSCRIPT.EXE” Then
 WScript.Echo “This script must be run under CScript.”
End If
‘ Get the new default VM path from the command-line arguments
Set namedArguments = WScript.Arguments.Named
If namedArguments.Exists(“path”) Then
 defaultVMPath = namedArguments.Item(“path”)
 WScript.Echo “Missing command-line argument”
 WScript.Echo “Usage: SetDefaultVMPath.vbs /path:” & chr(34) & “Default path to use for new virtual machines” & chr(34)
End If
‘ Attempt to connect to Virtual PC
On Error Resume Next
Set vpc = CreateObject(“VirtualPC.Application”)
If Err.Number <> 0 Then
 WScript.Echo “Unable to connect to Virtual PC.”
End if
On Error Goto 0
‘ Set the new default VM path
vpc.DefaultVMConfigurationPath = defaultVMPath



Note that while these scripts will set the default location – if the user chooses a different location when creating a new virtual machine, that location will become the new default virtual machine location. 

This means that these scripts are only really useful for customizing an initial deployment of Windows Virtual PC.  Alternatively you could run these scripts on logon to set the default path back to your desired location.