In Windows® Virtual PC (WVPC), Virtual Machine (VM) start-up and close behavior can be configured to have a customized user experience. Few start-up options can actually lead to perceivably faster launching of Virtual Applications. In this blog, we will discuss these options and settings along with their pros and cons. This should be helpful for you to understand the best performance tweaks that can be done with WVPC VM and the kind of impact it can have on your machines.
Once a VM is created, it can be started in Desktop mode from the Windows® Virtual PC Center. However Windows® XP Mode VM can be directly started from the Start Menu.
Figure 1: Windows® Virtual PC Center to create or launch a VM
If Integration Components (IC) are installed (recommended), then by default the VM tries to enable Integration Features (IF) on VM start-up. This behavior can be changed through VPC Settings -> Integration Features -> Uncheck ‘Enable at startup’. However the user always has the option to manually enable/disable Integration Features while VM is running, from the tools menu as well. The same can also be accomplished through script #1.
Start-up time of a VM may be reduced if this setting is disabled but Integration Features like Clipboard (copy/paste), Drive, Printer and Smart Card redirection will not be available. Also the POST screen of the VM booting would be visible.
This may be the ideal usage setting where VM needs to be used in isolation from the host or is only remotely accessed through Remote Desktop Connection etc.
Figure 2(a): WVPC Settings to change Auto-Enable Integration Features Figure 2(b): Manually disabling Integration Features
Script #1: Disable Integration Features at Start-up
This script will disable Integration Features for the default VM (or the specified VM, if <VMName> is passed as an argument to the script).
Similarly, a Virtual application can also be launched from Windows® 7 Host start menu once the application has been published from the VM. All published applications of a VM are listed under, Programs -> Windows Virtual PC -> <VMName> Application* in Windows® 7 Start Menu.
PS: Scripting provides a useful means to perform a number of operations on VMs such as Creating, deleting, changing VM configuration, states and tracking VM state, health and other information about it. PowerShell is another powerful medium to interact with the VM. The blog uses VBScript for code snippets. These code snippets can be saved as <ScriptName>.vbs file and executed in Windows® 7 command prompt with the following syntax: cscript <Scriptname>.vbs arg1
Starting a headless VM
Sometimes, you might want to start a VM in the back ground without any User Interface. This can be of great use for IT Administrators/Professionals, Developers & testers. For example if you want to reduce the latency of Virtual Applications start-up time, remotely use the VM through Remote Desktop Connections or execute some tests in isolation without any user interference.
This is referred as a Headless VM configuration.
Here is a sample VB script to start the VM in Headless mode.
Script #2: Starting a VM in Headless Mode
When host logoff, shutdown or restart is initiated, each running headless VM is first hibernated. This may cause some delay in host logoff, shutdown or restart. Also Integration Features cannot be enabled for headless VM. Additionally, user also has to keep a track of headless VMs as they run behind the scene i.e. without any User Interface.
Auto Start a VM
A VM can be configured to start at Windows® 7 start-up. When a VM is setup to start on Windows 7 Start up, it drastically reduces the time required for first time launch of Virtual Application. However, with this configuration, the VPC.exe will keep running, holding the resources like RAM allocated to the VM and speed up battery drainage on laptops. However in case of desktops the following configuration can help is faster launching of Virtual Application. Since the VM would be started immediately after login into Windows 7, there might be some impact on the responsiveness of the host for couple of seconds.
Auto Start a Virtual Application:
Copy the shortcut of the Virtual Application to start-up folder of Windows 7 that needs to be started on Windows 7 start-up. In this example, Virtual Application-Internet Explorer 6 has been set to auto start with Windows 7 start-up.
Virtual Application: %appdata%\Microsoft\Windows\Start Menu\Programs\Windows Virtual PC\<VMName> Applications*
Windows 7 Start-up Folder: %appdata%\Microsoft\Windows\Start Menu\Programs\Startup
Auto Start VM in Headless mode
Create a shortcut of script #2 under Windows® 7 start-up folder with the following target: cscript <pathoftheScript>\<scriptname>.vbs <”VMName”>
Figure 3: Set a Virtual Application to Auto-Start
Auto Start VM in Desktop Mode
VM can also be set to auto start with Windows® 7 start-up in desktop mode. This can be easily accomplished by adding the shortcut of the <VMName> .vmcx file (vmcx file is located in Windows® Virtual PC Center) in start-up folder.
Figure 4: Set VM to Auto-Start in Desktop Mode
Close a VM
A VM in Desktop Mode can be manually closed by the user, either from the user Interface (Figure – 5) or through scripts (refer script #3 for details). Notice that there are 4 options for ‘Closing’ a VM. Each option has its own benefits and use case.
Figure 5: Close VM options.
Hibernate: This is very similar to hibernate of a physical machine. The VM is initially set to Pause/sleep state and then VM memory is purged to a save state file (<VMName>.vsv). The difference in VM hibernate as appose to a Physical machine is that VM is unaware about hibernation or resume thereafter. Unlike the physical machine where the machine itself initiates hibernation/resume, here the Host does it for the VM. Hence, this operation doesn’t require ICs to be installed. This mechanism offers benefits like quick shutdown and resume, no data loss. This is the default close setting for XP Mode VM. This setting can be modified either through VPCSettings -> Close.
It is not recommended to migrate a VM in hibernate state as difference in processor architecture of the two host machines can render the save state useless. In such case, deleting the save state file would allow the VM to boot up, but may lead to data loss.
Alternatively VM can be hibernated through scripts. Script #2 can be easily modified to accommodate the same.
Shutdown: This would initiate a graceful shutdown of the VM. Since this is done by Guest OS it requires ICs to be installed in the VM. Here the scripts provide an additional option to force shutdown the VM. Shutdown of a VM is absolutely identical to a physical machine.
Turn Off: This is very similar to Powering off the machine. It is not recommended as it may lead to data loss or corruption of Guest OS.
Turn Off and discard changes: This option appears only when ‘Undo Disks’ is enabled. It will delete all data in the undo disk (.vud file). This option should be used with caution as it may lead to data loss.
Figure 6: Default close VM setting for XP Mode
Script #3: Enable prompt while closing the VM
However, shutdown in case of a Virtual Application does not involve any explicit User Interface. Let’s look at the VM state transitions that take place when a user interacts with Virtual Applications:
- VM will be started if it is not already running when the first Virtual Application is launched.
- When the last Virtual Application (launched by the user) is closed and none of the other Virtual Application’s window is opened, the VM hibernates after 5 minutes. Script #4 can be modified to set the value of the VMC tag: ‘ui_options/seconds_to_save’ to the desired time duration).
- While Virtual Applications are running and Windows® 7 host is logged off or shutdown, graceful (controlled) shutdown of VM is initiated.
- Similarly, if Windows® 7 host goes to hibernate or sleep state, the VM is paused. On host resume, the VM auto wakes up. This may also cause the Virtual applications to be unresponsive during this short time interval.
- In case of forced Host shutdown, VM is powered off abruptly.
Note: In case of headless VM, Windows® 7 Host logoff/shutdown/restart will always initiate VM hibernate/save.
‘Never Hibernate’ VM Setting
When the last Virtual Application is closed (launched by the user), the VM will go into hibernate state after 5 minutes by default. This is done to ensure that host resources are freed and battery drain can be reduced when no virtual application is running. This setting can be changed so that the VM never hibernates and subsequent Virtual application can be launched with minimum latency.
Script #4: Set VM to Never Hibernate
This script sets the value of VMC tag "ui_options\seconds_to_save" to 0 and hence VM would never be hibernated even after closing the last Virtual Application. This tag can also be used to increase or decrease the time to hibernate the VM when last Virtual application is closed.
Note: This tag doesn’t impact VMs running in desktop or headless mode.
In most of the cases, this would ensure faster virtual application launch, as VM doesn’t hibernates after closing the last virtual application (launched by the user). But in case of host restart, first virtual application launch will still take time as VM needs to be started first. This can also be tweaked by adding an entry of starting a headless VM on Window 7 startup (refer Auto Start VM in Headless Mode)
In WVPC, you can configure the VM start-up and close behavior using WVPC settings and the sample scripts presented above, to optimize the user experience and performance of VMs and virtual applications. Check out WVPC and Windows XP Mode today, and let us know what you think, either via the comments section here, or sharing your feedback on the WVPC and Windows XP Mode Forum on TechNet here.
Microsoft Virtualization Team