For the past few years I've used Microsoft Virtual PC (with the free test images) for testing browsers that won't coexist on a single machine (IE in particular). It's effective, although the image expiry makes things a bit tedious at times.

Windows 7 has changed the picture by including "XP Mode" - which is not really a "mode", but a virtual Windows XP instance. I was initially discouraged to find you can't run up multiple instances of XP Mode, but thankfully you can run up multiple variations of your XP Mode instance.

The effect is the same, so I can only presume it would take some licensing guru at Microsoft to explain the reasons we have to jump through some hoops to set up a multiple-IE test environment.

The goal

The setup I currently need:

  • One VM kept at IE6 (plus Firefox 3.0)
  • One VM upgraded to IE7 (plus Firefox 3.5 and Safari 4)
  • IE8 and latest Opera, Firefox, Safari, Chrome on the host system

In future I'll need to run up another VM with IE8, to allow for IE9 on the host system. I also tend to run up another image for use with beta and preview browsers.

Steps to get there

  1. Download and install XP Mode, Virtual PC and the XP Mode Update.
    • Don't fight it: use IE to download these packages. It makes the activation step much easier.
  2. Start XP Mode
    • Start → All programs → Windows Virtual PC → Windows XP Mode
    • You'll end up with a Windows XP SP3 instance up and running.
  3. Note this is a proper XP instance. Treat it like a real machine because that's basically what it is. That does mean you have to...
    • Install OS updates
    • Install your usual firewall and antivirus apps
  4. Run Windows Update as many times as required to get up to date - just be careful not to install a new version of IE during the updates.
    • I actually installed a firewall on the source image, although it's not clear if that could cause problems.
  5. The colour level is initially limited to 16bit, which really isn't adequate for.... well, anything I do with VMs. So...
    • To enable 24-bit without disabling integration features (hat tip for technique goes to the Sitepoint article about XP Mode and differencing):
      • Tools → Disable Integration Features
      • Log back in to XP Mode
      • Start → Run → mmc
      • File → Add/Remove Snap-in
      • Select Group Policy Object Editor, click Add then Finish, Close and OK.
        Go to Local Computer Policy → Computer Configuration → Administrative Templates → Windows Components → Terminal Services
      • Select the Limit Maximum Color Depth setting, select Enabled and set Color Depth to 24-bit
      • Close the console.
      • Set the desired resolution on the virtual desktop
      • Tools → Enable Integration Features.
    • To enable 32-bit colour, you need to disable integration features [Tools → Disable integration features]. So unless you really must have 32 bit colour, I'd stick to 24-bit colour.
  6. If you have any standard system tweaks you like to do (Folder Options spring to mind) now's the time to do them. Remember that any settings you change here will be done for all the subsequent test VMs.
  7. When you have your initial image patched, shut it down (don't hibernate it).
    • Note that you won't be running or using this image directly after this, but the VMs access it as their source image. Modifying the source image will break the variations, so it's recommended you don't touch it at all (set it to read only to be really sure).
  8. Create a new VM using differencing:
    • Start → Programs → Windows Virtual PC → Virtual Machines → Create virtual machine
    • I named the first one "XP Mode IE6"
    • Give each VM at least 256 megs (I give mine 512 and they're pretty happy).
    • In the "Add a virtual hard disk" step, choose "Create a virtual hard disk using advanced options".
    • Choose the "differencing" option and when you reach the "Specify a parent..." tab, point to "Windows XP Mode.vhd" which is the XP mode disk you just created. It will probably be in C:\Users\YOURUSERNAME\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines ...to find this, you may need to change your folder settings to show hidden files. I also found it useful to copy the location into clipboard then go back to the VM setup.
    • Repeat this step at least once to get an image with IE7.
  9. You should now see at least three VMs when you go to your Virtual Machines directory - the original Windows XP Mode, plus the new ones.
  10. Out of the box the images have IE8 blocked in Windows Update, so...
    • To keep IE6, basically just do nothing.
    • To install IE7, you'll have to download the IE7 installer and set it up manually.
    • To install IE8: run Windows Update → Custom → Restore hidden updates → select the IE8 update → Install Updates.
  11. IE6 and IE7 don't come with the developer toolbar installed, so you'll need to download the IE Developer Toolbar and install it on those VMs.
  12. On each VM, change the Computer Name to avoid networking clashes.
    • Go to System Properties → Computer Name → Change → enter a new computer name.
    • In a corporate environment I'd suggest you use some derivative of the host machine's name, in case your network guys ever need to find this extra "machine" they're seeing.
  13. Reminder... if you haven't set up security measures on your VMs, go do it now!

If you don't like the differencing method, there is an alternative method where you copy and edit the virtual machines. I've found the differencing method was pretty low-fuss in practice so I haven't tried the copy/edit method.

OS integration

On my machine I've found XP Mode VMs work like any other application... it's just that one window happens to be an entire instance of Windows XP.

There's no appreciable lag switching to the VM window even using Aero Flip (windows+tab) and you can move the window around on the screen with no issues.

Resizing the window or toggling full screen mode is an exception to the overall illusion that the VM is just another window. The VM treats the resize as an actual resolution change, with a 2-3 second pause while it resets itself. So far I haven't found that to be much of a problem since I very rarely resize my VM windows.

Going into full screen mode takes over the whole screen, same as for any remote desktop connection.

It's worth noting you can shut down the VMs and run virtualised applications like normal windows on the host machine, I just prefer running the VMs to keep the virtualised browsers together.

performance

I've been pleasantly surprised by the performance of XP Mode on my home machine. The virtual machines are responsive enough even when debugging with the IE Developer Toolbar. There's some lag, but nothing unmanageable so long as you accept that VMs are not performance machines.

The limited performance does mean details of your interaction animations - fades, slides etc - aren't smooth. A simple jQuery fade in IE7 on XP Mode steps through a short series of shades rather than an actual fade.

So the VM will be fine to do things like confirm a dropdown menu works and a fade effect occurs, but not to check that the fade is smooth. If you need high fidelity this solution probably isn't for you. Mind you, I've never seen a truly smooth VM for that kind of work.

Performance on my work machine, however, ranges from ok to slow motion. That is probably because I also run a Java IDE and full application instance; and it seems that can cripple pretty much any machine.

resource usage

My dev machines have plenty of RAM available, so I give each VM a potential 512megs to play with. But it's not like they're massive memory hogs - right now Task Manager is reporting a total of 50megs RAM used up by VPC and two VMs.

I would guess that there's some level of system cost being absorbed by other, less obviously named processes. But even with a lot of applications running at once, the VMs don't seem to take up huge amounts of RAM or peg processors (YMMV).

what about Virtual PC?

Setting up XP Mode includes installing Virtual PC, which implies that Virtual PC will work the same as it always did. However in my experience that's not true. I don't get a Virtual PC console and the browser testing images from Microsoft don't work very well - the integration features won't work and the VMs trap the mouse rather than behaving like a window.

If you really don't want to mess around with differencing and you rarely have to look at IE6, the free Virtual PC test images might be a solution for you. But I wouldn't want to use them all day every day.

getting files on and off the vm

Once you have your XP Mode VMs up and running, there are a few ways to get your files into the VM for testing (presuming you can't just point the browsers at a local web server).

  • The easiest option is to simply share the hard drives on the host machine (requires integration features)
    • Right-click the VM file → Settings → Integration Features → Drives. You'll need to restart the VM (not hibernate) for the new drives to show up.
    • All shared drives will appear in the VM as network drives and work accordingly.
  • Set up windows file sharing, the same as between two physical machines. Works much the same way as the first option, but is theoretically more secure.
  • Attach a USB drive to the VM, then detach and access it from the host. It's pretty low tech, but requires zero setup.
    • Use the "USB" menu in your VM to attach and release drives.
    • Note each USB drive will only be available to one machine at a time.
  • In some configurations, you might be able to copy and paste files between the VM and the host system. However even when it works, it really only copes with small files and it was very slow when I tried it (a 15meg file was painful and I gave up before a 100meg file had copied successfully). I don't know why it's so slow, but based on my experience I wouldn't recommend this option.

If you rarely need to copy or access host files from the VM, the USB option isn't too bad. I test a lot of flat files, so I go with the shared hard drives.

conclusion

Hoop jumping aside, XP Mode really is a pretty nice virtualisation system. It avoids the annoyance of expiring test images and integrates neatly into the host system. While I wouldn't switch to Windows 7 just for XP Mode, it's certainly a key feature for developers.