XP Mode Auto Install for Windows 8

New Tool: XP Mode Auto Install for Windows 8

Got inspired to work on this tool after reading this blog post on how to install XP Mode on Windows 8, and I was curious about getting it work. It reminded me of the time I worked on the P2V Migration for SA project for Microsoft (ha memories). Next step would be to get it working with a more modern OS like Win7 etc…, but I’ll save that for another day. 


This PowerShell script will programmatically do the following:

  • Download XP Mode from download.microsoft.com (will even download the correct language based on locale).
  • Extract out the XP Mode *.vhd file from the XP Mode Self Extracting file.
  • It will mount the XP Mode *.vhd file so we can add an AutoLogon patching script, along with a unattend.txt file.
  • The Patching script will:
    • Remove the old Virtual PC Integration Components
    • Install the Hyper-V Integration Components
    • Prepare the Virtual machine as a Remote Desktop Appplication Host.
  • Create a New Virtual Machine on the local host, with the XP Mode *.vhd as the primary disk.
  • Will Auto-Start the virtual machine, and then extract out the computer name generated by the client.
  • Finally, will create on the desktop, an RDP connection file to point to the new XP Mode Virtual Machine.
  • The default app is to point to Internet Explorer 6.0 (Evil)!

Do No Evil

What makes this tool bad/evil/horrible:

  • It does not perform any Windows Update Patching (an unpatched version of XP SP3 is bad).
  • It does not update IE to the latest version (IE 6.0 is bad)
  • We should all be working to get off of XP (XP end of Life is April 2014)
  • Bad, Bad, Bad


Some Interesting Points

  • Found all versions of XP Mode from download.microsoft.com and added them to the script. I haven’t done any testing.
  • I think the script does a good job of translating the Time Zone name to the Windows 5.x style TimeZone ID. It’s not perfect though.
  • I tried to keep the patching script small, everything handled within a simple batch script. The Integration Component uninstall/install programs handled gracefully, but KB961742 install required some state information to get around a reboot loop.
@if not defined debug echo off

if not exist %temp%\Sleep.vbs echo wscript.sleep 1000 > %temp%\Sleep.vbs

Reg.exe ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "App1" /t REG_SZ /d "cmd.exe /c %~fs0" /f
for /L %%i in (1,1,3) do ( TaskKill /im RunDll32.exe & cscript.exe //nologo %temp%\Sleep.vbs )

start /wait msiexec.exe /q /x {B0950C40-269A-11DD-BD0B-0800200C9A66}
start /wait d:\Support\x86\Setup.exe /quiet
if not exist %SystemRoot%\KB961742-v3.txt (
  Echo Done > %SystemRoot%\KB961742-v3.txt
  %SystemRoot%\KB961742-v3.exe /quiet

@echo Finished installation...
cscript.exe //nologo %temp%\Sleep.vbs

netsh firewall set service remotedesktop enable
reg.exe ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\TsAppAllowList" /v fDisabledAllowList /t REG_DWORD /d 1 /f
reg.exe ADD "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
reg.exe ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\WinLogon" /v AutoAdminLogon /t REG_DWORD /d 0 /f
Reg.exe DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "App1" /f

shutdown -l -f -t 00
  • When creating the Virtual Machine, I look for any “external” switches first, then I look for any other Virtual Switches, otherwise, I create an Internal switch:
if ( (get-vmswitch -switchtype External).Count -gt 0 )
  $NewVM = New-VM -Name "XPMode" -MemoryStartupBytes $VMMemory -VHDPath $XPVhd -SwitchName (get-vmswitch -switchtype External)[0].Name
elseif ( (get-vmswitch).Count -gt 0 )
  $NewVM = New-VM -Name "XPMode" -MemoryStartupBytes $VMMemory -VHDPath $XPVhd -SwitchName (get-vmswitch)[0].Name
  new-vmswitch -name "XPModeSwitch" -SwitchType Internal
  $NewVM = New-VM -Name "XPMode" -MemoryStartupBytes $VMMemory -VHDPath $XPVhd -SwitchName "XPModeSwitch"
  • When creating our *.rdp file, I will actually query the virtual machine itself through the Integration Components to find out the correct Computer Name. There is a minor change to the WMI Schema for Windows 8.1, but I think I have that taken care of. This code will “wait” for the XP Mode client to finish installation of the Integration Components and then allow the script to exit.
$NameSpace = "root\virtualization"
if ( [Environment]::OSVersion.Version -ge (new-object 'Version' 6,3) )
$NameSpace = "root\virtualization\v2"
$vm = gwmi -namespace $NameSpace Msvm_ComputerSystem -filter "ElementName='$($NewVM.Name)'"
While ( [string]::IsNullOrEmpty($ComputerName) )
  start-Sleep 30
  write-Verbose "Waiting... $($KVP.__Path)"
  $kvp = gwmi -namespace $NameSpace -query "Associators of {$vm} where ResultClass=Msvm_KvpExchangeComponent"
  if ( $kvp -is [object] )
    $xmlContents = ([xml](""+$kvp.GuestIntrinsicExchangeItems+""))
    $ComputerName = $xmlcontents.xml.INSTANCE | ?{ $_.PROPERTY.VALUE -eq "FullyQualifiedDomainName" } | %{ $_.PROPERTY } | ?{ $_.NAME -eq "Data" } | % { $_.VALUE}


https://skydrive.live.com/redir?resid=5407B03614346A99!1777 –> Install-XPModeWin8.ps1


2 thoughts on “XP Mode Auto Install for Windows 8

  1. I think I tried this before on Windows 8.1 and the XP Mode is BIOS locked to the Virtual PC BIOS in terms of product activation. How did you get around that? The BIOS string is different in HyperV

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s