Multi Boot into Windows 8 from VHD on Windows 7

Windows 8 is upon us, well at the time of writing Windows Developer Preview is available as a pre beta download.

I have written before on multi booting into VHD images in Windows 7 and so I wanted to see whether it is possible to multiboot into a Windows 8 VHD image from my Windows 7 desktop.

The short answer is no it doesn’t work, or at least not in the way I approached it. I need to read around a bit more, but I suspect I may need to be using the Windows 8 Boot Loader. It all seems to go well, except when I reboot and select the new Windows 8 multi boot menu item – when I do this it flips back into my default Windows 7 and runs the repair dialog. No harm is done, but the underlying error appears to be a failure to locate a boot loader.

Anyway, so as not to have wasted my time, below is what I tried to do :-( …all the below stuff works great for Windows 7 VHDs by the way ;-)

For the purposes of this article, let’s first create a working folder at the root of C drive, called VHD.

Step 1: Download one of the Windows 8 ISO images

I chose to download Windows Developer Preview English, 64-bit (x64).

Step 2: Create an Empty VHD File

Before we can generate a VHD image of our chosen Windows 8 version we must first create an empty VHD file into which we can generate it.

To do this, open file explorer and right click on Computer and select Manage, which will open the computer management window.

On the left hand side, select in the treeview node called Disk Management (Computer Management (Local), Storage, Disk Management) and then right click on it and select Create VHD (see screenshot below):

screenshot 1 create vhd
This will open a dialog similar to the one below. In this case we are creating a VHD file called Win8x64.vhd in our working folder, C:\VHD\win8x64.vhd, to expand dynamically upto a maximum size of 50GB.
scheenshot 2 Create VHD

This will create a new disk within Disk Management that looks similar to the screenshot below:

screenshot VHD DIsk

First we must initialise the new Disk. To do this, right click on the caption area and select Initialize Disk.

screenshot 1 Initialize VHD
Now select the MBR (Master Boot Record) option and click OK.
screenshot 2 Initialize VHD

Next we create a simple volume within the initialsed disk. To do this, right click on the disk area to the right of the caption and select New Simple Volume (screenshot below):

screenshot 1 New Simple Volume

This will open a wizard for which you generally just click next until finished, however ensure you select a drive letter to mount the disk. I chose to mount the disk as drive V (V:\). Screenshots of the wizard are shown below:

screenshot 2 New Simple Volume

screenshot 3 New Simple Volume

screenshot 4 New Simple Volume

screenshot 5 New Simple Volume

screenshot 6 New Simple Volume

Step 3: Create a Windows 8 VHD Image

Now we can generate the a VHD image of our chosen version of Windows 8 into the VHD.

To do this you will need two files:

  • imagex.exe
  • install.wim

imagex.exe

This file (imagex.exe) is part of the Windows® Automated Installation Kit (AIK) for Windows® 7, or WAIK for short.

This is a very large download (about 1.7GB) and we literally only want the one file out of it. Once installed search for this file (imagex.exe) and copy it to our working folder, C:\VHD\imagex.exe

install.wim

This file is within the ISO of the Windows 8 installation disk we downloaded in step 1. Mount the ISO image (or cut it to a DVD), search for this file (install.wim) which is under \\sources folder and copy it to our working folder, C:\VHD\install.wim.

Now open a command window (ensure it is run as Administrator), change directory to our working folder, C:\VHD and run the follow command:

imagex /info install.wim

This should produce an output similar to the following:

Available Image Choices:
————————
<WIM>
<TOTALBYTES>3272285556</TOTALBYTES>
<IMAGE INDEX=”1″>
<DIRCOUNT>15078</DIRCOUNT>
<FILECOUNT>71371</FILECOUNT>
<TOTALBYTES>12756775435</TOTALBYTES>
<HARDLINKBYTES>4870029526</HARDLINKBYTES>
<CREATIONTIME>
<HIGHPART>0x01CC6772</HIGHPART>
<LOWPART>0x7E5E349C</LOWPART>
</CREATIONTIME>
<LASTMODIFICATIONTIME>
<HIGHPART>0x01CC6847</HIGHPART>
<LOWPART>0x7D8CCFEE</LOWPART>
</LASTMODIFICATIONTIME>
<WINDOWS>
<ARCH>9</ARCH>
<PRODUCTNAME>Microsoft® Windows® Operating System</PRODUCTNAME>
<EDITIONID>Prerelease</EDITIONID>
<INSTALLATIONTYPE>Client</INSTALLATIONTYPE>
<SERVICINGDATA>
<PKEYCONFIGVERSION>6.2.8102.0;2011-08-23T22:28:58Z</PKEYCONFIGVERSION>
</SERVICINGDATA>
<HAL>acpiapic</HAL>
<PRODUCTTYPE>WinNT</PRODUCTTYPE>
<PRODUCTSUITE>Terminal Server</PRODUCTSUITE>
<LANGUAGES>
<LANGUAGE>en-US</LANGUAGE>
<DEFAULT>en-US</DEFAULT>
</LANGUAGES>
<VERSION>
<MAJOR>6</MAJOR>
<MINOR>2</MINOR>
<BUILD>8102</BUILD>
<SPBUILD>0</SPBUILD>
<SPLEVEL>0</SPLEVEL>
</VERSION>
<SYSTEMROOT>WINDOWS</SYSTEMROOT>
</WINDOWS>
<NAME>Windows DEVELOPERPREVIEW</NAME>
<DESCRIPTION>Windows DEVELOPERPREVIEW</DESCRIPTION>
<FLAGS>PreRelease</FLAGS>
<DISPLAYNAME>Windows Developer Preview</DISPLAYNAME>
<DISPLAYDESCRIPTION>Windows Developer Preview</DISPLAYDESCRIPTION>
</IMAGE>
</WIM>

We want to know the index of the OS version we are trying to create a VHD of. In the above example we want to create a VHD of Windows DEVELOPERPREVIEW, which is index 1.

Now run the following command:

imagex /apply install.wim 1 V:\

where in the example above, 1 is the index of the chosen Windows 8 version and V:\ is the previously mounted VHD Disk.

This operation will take some time. On my machine this was about 6 minutes, but once finished we now have a bootable VHD image of Windows 8. You will see an output similar to below:

ImageX Tool for Windows
Copyright (C) Microsoft Corp. All rights reserved.
Version: 6.1.7600.16385

[ 100% ] Applying progress

Successfully applied image.

Total elapsed time: 5 min 49 sec

Step 4: Create Multi Boot Option for Windows 8 VHD Image

Firstly run the following command:

bcdedit /copy {current} /d “Windows 8 Developer Preview”

The part above called “Windows 8 Developer Preview” can be anything you want. This is the text that will appear in your multi boot menu when you boot up your PC.

This will give an output similar to the one below:

The entry was successfully copied to {281d3e08-e237-11e0-a65a-69bf4724019b}.

This has just cloned the details of the OS you are currently running into the multi boot loader. Now we must edit the pertinent parts to make it use and be relevent to the new Windows 8 VHD.

Next run a command similar to this (edited appropriately for your environment):

bcdedit /set {CLSID_Number} device vhd=[C:]\VHD\disk1.vhd

The CLSID_Number is the one we were given in response to the previous command and the disk1.vhd will be the VHD file we created earlier. Take care to include all the characters, including curly braces and square brackets. On my machine I would have entered the following:

bcdedit /set {281d3e08-e237-11e0-a65a-69bf4724019b} device vhd=[C:]\VHD\win8x64.vhd

Next run another command similar to this (edited appropriately for you environment):

bcdedit /set {CLSID_Number} osdevice vhd=[C:]\VHD\disk1.vhd

Again, replacing the CLSID_Number and disk1.vhd parts. On my machine this would have been:

bcdedit /set {281d3e08-e237-11e0-a65a-69bf4724019b} osdevice vhd=[C:]\VHD\win8x64.vhd

Step 5: ReBoot Into Windows 8 VHD Image

You have now completed all the necessary steps to create a multi boot Windows 8 VHD.

All you need to do now is reboot your PC and select the new entry from the multiboot menu on startup.

When you first select the multi boot entry you will go through the usual Windows setup process. Once you have done this once you can simply copy the VHD file, and rename it and attach it along side the other one using step 4 above to avoid having to do the setup stage again and again.

As a tip I create one VHD, get it set up for my machine, then put a copy of it to one side to revert back to when I want a clean, new version again.

Optional Step

If you wish to get rid of the entry in the multi boot then simply run the following command:

bcdedit /delete {CLSID_Number}

Don’t forget to replace the CLSID_NUmber part, and if you cannot remember what it is then run this command first to find out what all the multi boot entries are:

bcdedit

Summary

I hope you find this useful. I find booting from VHDs a great experience and I hope you do too.

Installing Umbraco 4.5.2 on Windows 7

I was asked by a local business person whether I could help with their website but whilst being a competent .NET developer I have never used ASP.NET commercially.

The brief was based on some initial design documents they had paid a web designer for, but also to ensure the site was stylesheet driven and allowed the owner’s to maintain the content themselves. Some areas of functionality they were looking for beyond the typical business website were things like; eCommerce basket, blog, appointment booking, facebook and twitter integration, membership system and within this access to previous and future appointments and private records.

So, glossing over the rest of my research I found Umbraco (4.5.2 at the time) which seems to offer a good framework for what I needed, was a CMS (Content Management System) and so would allow maintenance by the owner and whilst there wasn’t a full library of components many people had already done what I wanted to do, the forums seemed very helpful and it was full ASP.NET based and so any ASP.NET component could be seamlessly integrated.

One route was to use the Web Installer but this wants to install SQL 2008 Express R2, which I am quite happy with but I had SQL 2005 already installed on my development system and did not want to also have 2008 on it. So, as I couldn’t use the Web Installer I was faced with a manual installation.

I download the latest version (4.5.2) from codeplex (http://umbraco.codeplex.com/releases) in .NET 4.0 flavour (3.5 was also availble) and then proceeded to install it. Here I started to struggle, probably due to my unfamilliarity with using ASP.NET, but it is at this point I decided to start documenting my experience as I didn’t seem to be alone in this situation.

  1. Create a Windows Account to run the website under.

    I did this via right-click within file explorer on Computer, Manage and then under Local Users and Group created a User called umbraco45.

  2. In IIS, create a new Application Pool running in .NET 4.0 with an Identity of the above Windows Account.

    I created an Application Pool called umbraco45, selecting the Windows Account I created above as the xustom account to run under.

  3. Right click on downloaded zip file and click the ‘Unblock’  button.
  4. Unzip and place the contents under C:\inetpub\wwwroot.

    When I did this, the contents of the zip were in a root folder called build. I renamed this folder to umbraco45 and so in my case I ended up with C:\inetpub\wwwroot\unbraco45.

  5. In IIS, right click on the folder copied there earlier and click Convert to Application and set the Application Pool to the one created above.
  6. In SQL Server create a SQL Login (under Security), using SQL Server autentication.

    In my case I called this umbraco45. Ideally I would have used Windows Authentiation, but the Umbraco installer only seems to work with SQL Server authetication. At this point you may need to turn ‘Mixed Mode Authentication’ on within SQL Server.

    Regarding using Windows Authentication – I will revist this after installation.

  7. Create a new database.

    In my case I called this umbraco, using the default settings.

  8. Create a User within the above new database and map this to the above Login and set the Roles to; datareader, datawriter, ddladmin.Again, in my case I created a User called umbraco45.
  9. At this point you should be able to run the installer, however it will fail for two reasons; file access security and ASP.NET timeout.During installation the web.config needs to be updated and various components are downloaded into the file structure below c:\inetpub\wwwroot\umbraco45, so we must amend the file permissions.

    In IIS, right-click on the umbraco website (umbraco45 in my case) and select Edit Permissions. On the security tab click Edit in the top part and add the Windows Account we created earlier (in my case umbraco45). By default this account gets “Read & execute”, “List folder contents” and “read” permission. Also check the “Write” permission.

    When the installer nears the end it downloads and installs several components – assuming you select Runway example and some components. This takes too long and times out so to extend the timeout period edit the web.config file.

    In my web.config file there is an element like this:

    <httpRuntime requestValidationMode=”2.0″ />

    Edit this to look like this (adding attributes maxRequestLength and executionTimeout):

    <httpRuntime requestValidationMode=”2.0″ maxRequestLength=”10240″ executionTimeout=”36000″ />

  10. Run the installer by right-clicking in IIS on the umbraco website and selecting Manage Application | Browse…In most cases you just select next, but on the database page remember to enter the appropriate details.

    In my case I am not using a DB Instance and soI changed “.\SQLEXPRESS” to just “.” and the database name and user were both umbraco45.After this the page requesting to install a foundation (Runway) allows you to select other components. I selected all the recommended ones, plus XSLT search and sitemap.

    It is this stage that takes a very long time…so long you think it has hanged. It does work if you leave it long enough, about 10 minutes in my case.

Installation should now be complete. You can now remove the above file permissions entirely (not just the write but the entire User permission) and the extended timeout settings. You will need to put these back is you wasnt to download any new components.

I shall write again about my learning experiences of trying to use Umbraco.

Windows 7 Dual Boot to VHD

I recently got my shiny new copy of Windows 7 Professional (x64) so decided to give it a whirl. Now I was already using Vista Business (x64) and I have been quite happy with it, so will I find Windows 7 that much different?

Well, rather than migrate (which is an option with Vista) I chose to wipe and start again and the install was trivial – then I started to look into some of the new features and the one that has grabbed my attention the most is the ability to dual boot from a VHD. Why bother when you have Virtual PC to host the images you may ask? Well two reasons for me really:

  1. Running a Virtual PC requires the overhead of running you main OS as the host, so booting directly into it would eliminate that waste of memory, processor use etc.
  2. Booting directly into a VHD treats it like a real installation and so uses real driver onto the real hardware – it doesn’t behave like a Virtual machine and so you can test how installations of drivers may really affect the OS and you get a true OS performance rather than some slower interpretation.

 So, here is my step by step on how I did it – because believe me it took a few goes and some to get it to work!

1. Install Windows 7 as your main OS

It is useful to note at this point that you do NOT need to leave space on the drive for additional partitions etc as VHD dual booting does not need a partition of its own – it exists within the VHD file on the main partition. If however you want to share data between various dual boots you will need a common ‘D:’ drive or similar.

2. Either create you own VHD image or do as I did and download a ready made VHD from Microsoft.

Here is a link to the download http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=606ae07e-b7db-405b-974b-dd61fc41add4. If this link doesn’t work, I just searched the microsoft ‘Downloads’ for “Windows 7 VHD”.

This gives you a 90 day evaluation copy of Windows 7 Enterprise – but the 90 days starts nicely from when you first use it, not from some preset date 89 days ago! I extracted the VHD (comes as a 3 part rar) which contains the file Win7ENT90DAYS.vhd (as well as loads of other files/stuff you don’t need).

3. Register the VHD for Dual Boot

Now here’s the interesting part. Place the VHD file ‘somewhere’ on your main drive – in my case I created a root folder call “VHD” and placed it in there. So on my machine the file is located as follows:

C:\VHD\Win7ENT90DAYS.vhd

Now open a Command Prompt ‘As Administrator’ and enter the following command:

bcdedit /copy {current} /d "My Windows 7 Enterprise"

This will give a response similar to this:

C:\>bcdedit /copy {current} /d "My Windows 7 Enterprise"
The entry was successfully copied to {aefc86cc-c9b9-11de-a443-86288b18463d}.

Now enter the following two commands, using the GUID generated in the above command:

bcdedit /set {GUID} device vhd=[C:]\VHD\Win7ENT90DAYS.vhd
bcdedit /set {GUID} osdevice vhd=[C:]\VHD\Win7ENT90DAYS.vhd

This will give a response similar to this:

C:\>bcdedit /set {aefc86cc-c9b9-11de-a443-86288b18463d} device vhd=[C:]\VHD\Win7ENT90DAYS.vhd
The operation completed successfully.

C:\>bcdedit /set {aefc86cc-c9b9-11de-a443-86288b18463d} osdevice vhd=[C:]\VHD\Win7ENT90DAYS.vhd
The operation completed successfully.

This has registered the VHD file as a potential Dual Boot and will appear in the list as “My Windows 7 Enterprise”

ReBoot and you should now see the Dual Boot menu and simply choose the new entry “My Windows 7 Enterprise”.

GOTCHAS et al

I stumbled at a few points getting this far when using the bcdedit utility, so take careful note of the following points:

  • include the curly braces – the curly braces around the GUID form part of the instruction
  • include the square brackets – the square brackets around the drive letter (in this case [C:]) are important and form part of the instruction

Removing the Dual Boot Entry

Should you wish to remove the Dual Boot open a Command Prompt ‘As Administrator’ and enter the following command:

bcdedit

This will list all the currently registered entries. One of these entries will be ”My Windows 7 Enterprise”. This will give a response similar to this:

Windows Boot Loader
-------------------
identifier              {aefc86cc-c9b9-11de-a443-86288b18463d}
device                  vhd=[C:]\VHD\Win7ENT90DAYS.vhd
path                    \Windows\system32\winload.exe
description             My Windows 7 Enterprise
locale                  en-US
inherit                 {bootloadersettings}
recoverysequence        {aefc86c1-c9b9-11de-a443-86288b18463d}
recoveryenabled         Yes
osdevice                vhd=[C:]\VHD\Win7ENT90DAYS.vhd
systemroot              \Windows
resumeobject            {aefc86bf-c9b9-11de-a443-86288b18463d}
nx                      OptIn

Note the GUID and use it in the following command:

bcdedit /delete {GUID}

This will give a response similar to this:

C:\>bcdedit /delete {aefc86cc-c9b9-11de-a443-86288b18463d}
The operation completed successfully.

So there you have it…simple isn’t it. Now I can have multiple Dual Boot options for various reasons using a single VHD image as the starting point for each of them.

I would suggest configuring the first one, then boot into the main OS and copy the VHD (as a backup) so you can reset back to it is you want – and to do that you don’t even need to use the Command Prompt, just replace the VHD whilst in the main OS.



Display driver nvlddmkm stopped responding, but has successfully recovered.

Time to upgrade my PC…I have being using a single core AMD 3200 Athlon for quite a while now and so I set forth on a new PC build. After many many hours of research (a.k.a. surfing) I have ordered all the parts I need:
 
Monitor: 22" LG Flatron LCD Wide (L226WTQ)
Motherboard: ASUS P5K-E/Wifi AP (P35)
Processor: E8400 Core 2 Duo (wolfdale 45nm) 3GHz, 6MB L2 with stock cooler
Graphics: Zotac 8800 GTS 512 (G92)
Memory: 2GB (2 x 1GB) Crucial Ballistix DDR2 8500 (1066MHz)
HDD: Samsung Spinpoint T166 500GB 16MB Cache (x2 arranged in RAID0, ‘striped’)
DVD RW: NEC Optiarc SATA II
Case: Antec Solo
PSU: Antec TruePower TRIO 550W (triple rail)
plus a new MS Keyboard and Optical Mouse
 
I managed to grab a new wolfdale on the first day of release so eagerly awaited its arrival, which despite using eBuyer’s 5 day free delivery came very quickly in just a couple of days.
 
Putting it all together was easy and the Solo case was simple to access. Turned it on and blimey it all worked first time. Single beep, BIOS POSTed successfully – brilliant…but I needed to flash the BIOS as the motherboard didn’t fully understand the wolfdale E8400. This was also a breeze, using a USB pen direct from the BIOS.
 
This was all going too well…installed Vista Business Edition (I was already using this on my existing Athlon 3200 1GB system) and that was easy too. It only takes about 20 minutes to get Vista fully installed. It did however take me another 20 minutes to get all the ASUS motherboard drivers installed :-( . Then I took an image using the built in Vista Backup software (in Control Panel) which takes a complete backup of the system while it is running and that fitted comfortable on a single DVD. This image can be restored by booting to Vista install disk and full recovery is done within 20 minutes.
 
I put a few additional bits of software on, like the monitor drivers and the NVidia driver (192.25) and I was just about to move on to installing the main software when I though I’d just have a browse at the graphics card setting in the NVidia Control Panel. Then it happened…the spinning ‘NVidia Eye’ graphic on the first tab paused and I got a task tray pop-up advising me that ‘The display driver nvlddmkm stopped responding, but has successfully recovered.". then the ‘eye’ moved a bit more then another pause and the same message appeared again…this continued happening every couple of seconds then the BSoD (Blue Screen of Death).
 
Vista had bombed out big time.
 
I rebooted, tried again and no matter what drivers I tried it just kept happening. I read around on the forums and it seems lots and lots of people are getting the nvlddmkm error and there is no single resolution for it. Even MS have tried releasing updates, but none of these things fixed my problem. All the posts I read were about freezes in games, but I was getting it every couple of seconds in the NVidia Control Panel.
 
So what is the problem then? I ram MEMTEST for almost 24 hours – perfect results. I ran Prime95 – utilising both cores for a few hours – perfect results. I could test the Graphics card as this was the problem – then I stumbled on some posts regarding underpowered PSUs.

Then I even tried wiping the system and installing XP. Whilst this was more stable, Far Cry graphics didn’t work properly and F.E.A.R. would even start, saying something like ‘Cannot initialize engine’. This found a couple of posts suggesting the system was underpowered – but I had bought a brand new Antec truePower TRIO 550W (SLI certified) – so this should be fine shouldn’t it – if it is SLI certified and I am only running 1 card surely this would be OK. A little more digging and I discovered that the BIOS reported by 12V only delivering 11.6V and when Vista was running (am I glad I took that image now!) SpeedFan showed on 11.31V.

I contacted Antec and they said based on my Voltage reading the PSU was faulty – but by the time they responded I had already taken it into my own hands and returned it to Amazon. Their returns service was excellent. I printed off a postage paid label, popped it in a box, completed DHLs online pickup request and DHL collected it from  my workplace the next day.

I have decided that a 3 rail PSU may or may not be an issue, but I am taking no changes this time, so I have prder a Corsair TX 750W single rail PSU, which shuld arrive this week…please oh please let it fix my Vista woes. I so want to get the PC working properly and I really wantr to be able to play some games in Vista to test out the new grapics card (8800 GTS 512)…plan to play F.E.A.R. then challenge it with Crysis.

All this has comsumed two weekends of my time (grrrrrr), but is that light I see at the end of the tunnel?

I shall update this BLOG once I have received the new PSU…pray with me…Oh Lord make my Vista work?!

 
 
Well – as promised, I am updating this Blog entry…the new Corsair PSU did arrive but it did not address the problem – however I returned the PSU as it was too noisey and swapped it for another (this is my thrid now!) – a Seasonic S12 Energy plus. I am very pleased with this PSU and it is lovely and quiet – but it also did not address the problem.
 
So – I think I can be confident it isn’t the PSU, but it still loks like a lack of power to me. Next, I tried returning the Graphics Card (Zotac 8800 GTS 512) and ordered a new replace – this time opting for a cheaper 8800 GT (Play Value 8800 GT 512, which turned out to be a Palet 8800 GT 512). I am very pleased with the Palet as the fan is very quiet during normal useage and only ramps up during gameplay and I like the little utility that came with it called VDOTool as apart from allowing me to manually control the fan spped also allows me to change the MHz setting on the 3 main Graphics Card chips/memory.
 
In-between these two graphics cards, I borrow a friends ‘retired’ 6800 GT and with that I had no issues with the driver so maybe it was the card all along – but then the 800 isn’t so power hungry.
 
8800 GT arrived – so popped it in and tried the NVidia control panel and so far so good, so ran 3DMark06 – which black screened on me and returned to the desktop with the same old driver problem…ahhhhhhhhhhhhh
 
Finally I started fiddling with various setting in the BIOS and to my surprise found that increasing the NorthBridge voltage fixed the problem – I can now run 3DMark all the way through without error (11333 btw).
 
So, on my ASUS P5K-E motherboard I am now using all the default settings but with the components I don’t nee turned off (such as Floppy, Wireless, JMicron, Firewire etc) and changing only 2 settings:
 
1) Change DRAM Frequency from Auto to 1066 (as otherwise it tries to use default 800 it seems)
2) Change NB Frequency from Auto to 1.4V (I am assuming it was running at 1.25V as that was the only explicit value available to select below 1.4V).
 
I’d love to hear from anyone who has had this problem and found that upping the NB Frequency has fixed for them too?
 

.NET Resources, Settings and user.config Upgrade

I mainly write .NET 2.0 winform/desktop applications and have been using the Visual Studio Resources and Settings "strongly typed" mechanism. I have found this feature, that effectively comes free with Visual Studio, to be fantastic.
 
The Resources mechanism allows me to very simply create Resources of various types and know that they do indeed exist at compile time, unlike .NET 1.0/1.1, where I could easily create entries but I could easily use the key wrong into the ResourceManager and not realise this until I got an empty string or similar at runtime when I was expecting a value of some sort.
 
The Settings mechanism is also very similar and allows me to specify whether the setting is application or user oriented. Generally I find most of my entries are user oriented as I mainly use Settings to store application options, such as those entries you might find in the Options dialog box and the location and state of the application window when it was closed.
 
This was all going really well, but each time I released a new version all the Settings would revert back to their original default settings. I needed to find a way to upgrade an application in such as way that the user settings would be kept from a previous version of the software.
 
Changes to the defalt settings are stored in a file called user.config in a location below the users "Documents and Settings" (XP) or AppData (Vista) …\Company Name\Application Name\Version, e.g. [user]\MyCompany\MyApplication\1.0.0.0. The next release of the software reads/writes the user.config to a different version folder, e.g. [user]\MyCompany\MyApplication\1.0.1.0.
 
I did the usual Google and found a few similar articles talking about ApplicationBase.Upgrade(), although it took me about two hours to actually get it to work!! and as it turned out I did it right within the first 10 minutes but thought it wasn’t working. So to save you all the hassle here is what I did. Now it may be that my problems stemmed from the fact I was using Vista, but the same issue that caught me out may also be true of XP.
 
In the main() method of my winform application (before calling Application.Run) I wrote (C#) code like this:

if (MyDefaultNamespace.Properties.Settings.Default.Application_UpgradeRequired)

{

    try

    {
        MyDefaultNamespace.Properties.

Settings.Default.Upgrade();

        MyDefaultNamespace.Properties.

Settings.Default.Reload();

    }

    catch (Exception exception)

    {

        // Squash and continue without performing the upgrade

    }

    finally

    {

        /* Whether we succeed or fail flag upgrade as done.

         * We don’t want to try again next time even if we failed
         * as once the app has been run up once the user may have made
         * manual changes and we don’t want to oberwrite them.
         */

        MyDefaultNamespace.Properties.

Settings.Default.Application_UpgradeRequired = false;

    }
}

You can see from the above code that all the work is really done in the MyDefaultNamespace.Properties.Settings.Default.Upgrade() but what happens when you call this?
 
Essentially, it somehow knows what the last version was (don’t know exactly how it knows, but I guess it is based on examining the sibling version folders and deducing the previous version). If there is not previous version then nothing happens. If there is a previous version but no user.config is found (or something is wrong with it) then it raises an exception. But given it finds a previous version, any entries in the previous version that still exist in the new version are carried forward, any that do not are ignored. It seems you can use "NoSettingsVersionUpgradeAttribute" on the Settings wrapper class to prevent it being upgradeable, so you could split you Settings into two (or more) resource files, one that is Upgradable and one that is not.
 
You can use MyDefaultNamespace.Properties.Setting.Default.GetPreviousVersion("MySetting") to retrieve a value of a specific previous setting, which can be useful if either you only want to upgrade a few select items, or perhaps you changed the name of a setting in the latest release and want to bring forward th value from the previous version when it was called something else.
 
The issue I fell foul of was that despite there being a previous version, calling Upgrade() didn’t seem to do anything. On examination I found that my original version had gone into a folder something like this:
[user]\MyCompany\MyApplication.exe_Url_hwk1afgxmxf35sa0voi4agxgxtjhgmdn\1.0.0.0
but the new version had gone to:
[user]\MyCompany\MyApplication.exe_Url_qibjmlo5qfk3hyz4ev3ujyddthf0njla\1.0.1.0
I figured that because the version folders were not siblings that was why it didn’t work – which as it turns out was right, but why was the application creating a different application folder? I tried running the application in Visual Studio in both Debug and Release mode but got the same results, then as a final test I updated my installer with the new application and installed it, and then it worked! Yes, once installed the version folder 1.0.1.0 appeared below the original "MyApplication.exe_Url_hwk1afgxmxf35sa0voi4agxgxtjhgmdn" folder…grrrrr.
 
I think maybe the reason there being a different application folder was down to Vista security stuff, as XP doesn’t seem to create such weird application folder names, so maybe this is just a "Vista Developer Beware" issue.
 
As an aside, and to explain a little of the other code above. I create a new Setting in my application called "Application_UpgradeRequired" as a boolean and set it to true. I then used this to determine whether I had tried to upgrade before, as the first time I upgrade I set this to false to prevent it upgrading again. I just squash any errors that might have occured, but you could offer MessageBoxes or whatever to ask "Do you want to try again next time" or to ask whether the user wants to migrate previous setting in the first place.
 
So, if you find it is not working during your development/unit testing don’t worry it is Visual Studio and/or Vista messing with you…all will be well once installed and tested as a real application.

InstallShield 2008

Well, seems like I finally got myself a Blog – now all I have to do is get into the habit of putting stuff on it…so to kick if of I am going to do my first blog about InstallShield 2008.
 
I recently had the dubious pleasure of having to create a brand new set of installer for my companies product set and to do this I opted to use InstallSheild 2008 Premier.
 
Why Premier – well the main reason was that we use MSBuild and to get the installer to be auto built I needed to have InstallShield installed on the build machine, but this is not where I want to work when I create the scripts, so the choice was either buy two copies of InstallShield 2008 Professional or buy a copy of Premier as that comes with 10 licenses for a StandAlone command line installer…the latter was the cheaper alternative. Sure I get other features too, but if I could have bought the standalone licenses separately I would have.
 
As a first attempt I just tried to keep things simple and replicate the current installer organisation, which was done with VS2005 deployment projects. This meant that I firstly needed to create about 12 MergeModules (MSMs) and a couple of MSIs. This proved to be harder than you might imagine so in the end I simplified it and stuck to just 8 MSMs and 2 MSIs.
 
Problems that I encoutered for which I found resolution (via Macrovision InstallSheild maintenance support) were:
 

How do I get the CustomerInformation dialog All Users/Just Me radio buttons to appear?

It seems that this can only be achieved by using the DirectEditor and meddling directly with the installer tables. Essentially I needed to ‘drop’ two rows from the ControlCondition table, namely the two rows where Dialog=CustomerInformation and Control=RadioGroup.

This seems very odd to me as after-all, the dialog if available in the editor, yet I had to resort to manually editing the installer tables to get them to appear – but this is the way to do it so say Macrovision support.

Installing .NET 2.0 Framework was included, but when installed on a .NET-less machine it offered to install the Framework as an optional installation – whereas I wanted it to be mandatory. How do I make the inclusion of .NET 2.0 Framework mandatory?

It was easy to include the .NET 2.0 Framework via the Release Wizard but the dialog does not offer any configuration for the optionality of the installation. It turns out that selecting the Release node on the project tree display more information in the right pane that is made available in the Release Wizard and within that pane are a series of tabs, one of which is called .NET/J# and on there is a Yes/No option (default Yes bizarely) for ‘Display .NET option dialog. Set this to No and it now installs .NET 2.0 Framework seemlessly as part of the main installation.

This however has now brought with it a new problem. Whether .NET 2.0 Framework is already on the machine or not, this now requires a reboot of the machine following installation – when this is not the case, so now I need to find out why it thinks this.

Of the issues yet to be resolved:

  • PreCompile in MSIs uses the old .NET 1.0 NGen interface, even if I change the setting to ensure it is using the .NET 2.0 Framework’s NGen.exe it creates a custom action using the older style (i.e. does not use "install"/"uninstall" and therefore does not use the new Dependencies PreCompilation that .NET 2.0 NGen is capable of. I found a way round this for now but it required manual editing of the installer tables again – if you wanna know what I did then blog me and I’ll explain.
  • PreCompile does not seems to work at all for MSMs
  • I get lots of ICE30 errors when I build one of my MSIs with "compile to single setup.exe" turned on, but do not get these errors if I leave file uncompressed on the file system. I am awaiting a proper resolution to this, but in the meantime I was advised to turn off the ICE30 validation checks…not a good resolution but I am having to do this at this time.

Well, that’s enough for now…lets see if anyone reads this!

 
Follow

Get every new post delivered to your Inbox.