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.
1: Option Explicit ' Force explicit variable declaration.
3: Dim defaultVMTag, defaultVM, objArgs, objVPC, vmName
4: Set objArgs = WScript.Arguments
5: Set objVPC = CreateObject("VirtualPC.Application")
7: defaultVMTag = "default_vm"
8: defaultVM = objVPC.GetConfigurationValue(defaultVMTag)
10: if objArgs.Count < 1 Then
11: WScript.Echo "Syntax: cscript <scriptname>.vbs <”VMName”>"
12: WScript.Echo "Considering default VM."
13: vmName = defaultVM
15: vmName = objArgs(0)
16: End if
20: Sub DisableIF()
21: Dim vmcTag, objVM
22: vmcTag = "ui_options/use_enhancedmode"
23: Set objVM = objVPC.FindVirtualMachine(vmName)
25: if objVM is Nothing Then
26: WScript.Echo "VM not found: """ + vmName + """"
28: WScript.Echo "Disabling Integration Features at Startup for the VM: """ + vmName + """"
29: objVM.SetConfigurationValue vmcTag, False
30: WScript.Echo "Integration Features at start-up disabled successfully"
31: End if
32: End Sub
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
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.
18: WScript.Echo "Starting VM: """ + vmName + """"
21: Sub StartHeadlessVM()
22: Dim objVM
24: if objVM is Nothing Then
25: WScript.Echo "VM not found: """ + vmName + """"
27: Dim objVMTask
28: Set objVMTask = objVM.Startup()
29: 'Set objVMTask = objVM.TurnOff() 'Immediately Turns Off/Powers Down the VM
30: 'Set objVMTask = objVM.Save() 'Hibernate the VM
31: 'Set objVMTask = objVM.GuestOS.Shutdown(0) 'Controlled Shutdown
32: 'Set objVMTask = objVM.GuestOS.Shutdown(1) 'Forced Shutdown
33: objVMTask.WaitForCompletion -1
34: WScript.Echo "VM Started : """ + vmName + ""
35: End if
36: End Sub
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.
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.
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
Create a shortcut of script #2 under Windows® 7 start-up folder with the following target: cscript <pathoftheScript>\<scriptname>.vbs <”VMName”>
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.
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.
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.
20: Sub PromptAtClose()
21: Dim vmcTag, objVM
22: vmcTag = "ui_options/onclose_showmessage"
27: WScript.Echo "Enable prompt on VM close: """ + vmName + """"
28: 'This will enable prompt at close. User can then choose the close method
29: objVM.SetConfigurationValue vmcTag, True
30: 'To set the default behaviour at VM close. No prompt will be thrown in this case
31: 'and default action can also be set
32: 'objVM.SetConfigurationValue vmcTag, False
33: 'objVM.SetConfigurationValue "ui_options/onclose_defaultaction", "save" 'save/shutdown/turnoff
34: WScript.Echo "Close option set successfully"
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:
Note: In case of headless VM, Windows® 7 Host logoff/shutdown/restart will always initiate VM hibernate/save.
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.
21: Sub SetValue()
22: Dim vmcTag, objVM
23: vmcTag = "ui_options/seconds_to_save"
24: Set objVM = objVPC.FindVirtualMachine(vmName)
25: if objVM is Nothing Then
26: WScript.Echo "VM not found: """ + vmName + """"
28: objVM.SetConfigurationValue vmcTag, 0
29: WScript.Echo "VM: """ + vmName + """ set to never hibernate"
30: End if
31: End Sub
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.
*This may get localized based on Windows® 7 Host language.
Microsoft Virtualization Team
How do you copy the sources in this article?
how do i USE these scripts? If I copy it from this page, where do i PASTE it? I'm looking to use script 4 to auto-hibernate xpmode after closing the last integrated app...
>> Note: In case of headless VM, Windows® 7 Host logoff/shutdown/restart will always initiate VM hibernate/save.
Is it possible to change above behavior with registry or some hidden configuration files?
There's a usability conflict in 7's XP Mode between published applications and the default Hibernate option when closing the VM. Specifically, when the explicitly-started VM is left Hibernated, attempts to launch published apps via 7's Start Menu UI will fail because the user account is already logged on (i.e. remains that way within the Hibernated session).
I know I can set XP Mode to pop up a dialog when the session is closed, from which I can choose Shutdown rather than Hibernate, and this I've done.
But I'd like to go further, and set Shutdown to be the pre-selected default within that dialog. In other words, I don't want every [X] to shutdown without showing the dialog first; I want to see the dialog every time, but with Shutdown and not Hibernate as the pre-selected choice.
How would i start up the VM in headless mode without a user logging in?
Why is it not some command-line arguments for this application? Would be sooooooo much easier
Has anyone experienced longer shut down times when shtting down a Windows 7 laptop running Virtual XP?