Repairing Hibernated Windows XP Mode.

Illustration

I like Windows XP Mode a lot. As soon as I need to test something in XP, it is there. As soon as I am done, it just gets hibernated and waits for next chance to be used.

After upgrading my BIOS I could not get it to start anymore. It just said “‘Windows XP Mode’ could not be restored because either host processor type mismatch or lack of hardware-assisted virtualization support in the system.” I just love those messages that pinpoint issue to few unconnected solutions…

Fortunately (since I already used that Virtual machine and since Windows XP mode does not require hardware-assisted virtualization support anymore) I could quite easily scratch one error cause and focus my attention only to host processor type mismatch.

My BIOS error got Virtual PC into thinking that restoration would not be wise move. Since I had no idea myself whether this would be good move or not, I decided just to delete hibernation files and reboot machine.

First I had to find configuration file. I had not need for one that ends in .wmcx since there is absolutely nothing of any significance there. I needed one that ends in .vmc and it is usually next to virtual disk (mine was at C:\Users\Josip\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines\Windows XP Mode.vmc). There is lot of data in it but I was interested only in section.

...
  <settings>
    <configuration>
      <next_id type="integer">1</next_id>
        <saved_state>
          <path>
            <absolute type="string">C:\Users\Josip\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines\Windows XP Mode.vsv</absolute>
            <relative type="string">.\Windows XP Mode.vsv</relative>
          </path>
        </saved_state>
      </configuration>
    ...
  </settings>
...

In this section there was data that defines where hibernation support files can be found. To make machine forget that it was hibernated, I only had to DELETE this section. Once that is done I could start machine once more.

P.S. This same recipe should be valid for any other hibernated Virtual PC machine.

Fixed Width Columns in ListView

I like .NET’s ListView control and I often end up using it in places where even ListBox would suffice. ListView with single column in Details view is exactly look that I usually shoot for.

Of course, width of column needs to be adjusted in order to maximize usable space. This is easily done by simply resizing column to fit width of ListView but with some space reserved for vertical scrollbar. Here is code for e.g. Form_Load:

listView_columnTest.Width = listView.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth;

And, if there weren’t any users, that would be enough. Problem is that any user can change with of column and thus disturb our delicate balance :). Solution is in handling ListView.ColumnWidthChanging event. Somebody would expect that setting e.Cancel to true would be enough but this is actually not a case. Full solution requires two lines:

private void lsvFilters_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e) {
    e.NewWidth = ((ListView)sender).Columns[e.ColumnIndex].Width;
    e.Cancel = true;
}

VHD Attach 2.00 (Beta)

VHD Attach was created to scratch my itch when it comes to working with virtual disks. As things go, that also meant that some corners were cut. As application went freeware, much of those corners were fixed. One that remained was DISKPART.

You see, attaching was done via API, but detaching of drive was done from command line via DISKPART and then results were parsed. This particular operation was very prone to error when it comes to localized versions of Windows. I will not even get into performance issues with it - let’s just say that DISKPART is not quickest program to initialize.

This version of VHD Attach finally replaces DISKPART with direct usage of Virtual Disk Service and thus it should handle LIP more gracefully (although program remains English-only).

Without further ado, download is available here.

Comments

Illustration

For long time this blog dwelled in sub 50 visitors range. I was basically writing for my friends and occasional bystander. Comments were few and far between. As time went by and Google did it’s magic, I got more visitors and, unfortunately, more comments. Why I say unfortunately? Because most of comments are pure spam.

I like seeing comment. I like it even more when I get e-mail with some insight. However, these comments just contain text that is designed to massage my ego (e.g. “Aw, this was a really quality post”) and link at bottom is designed to grab occasional nervous clicker. Do not misunderstand me, I like my ego massaged, I despise link that follows.

Blogger platform helps me here with “great” spam filtering capabilities. I wrote great in quotes for a reason - this great platform hasn’t caught single spam comment. And thus all comment handling stays my chore.

I have no idea how to efficiently handle this. Going through all comments and deleting spam seems like only way to do it. However, do not hold it against me if I miss one or two.

Just don’t click them.

Benchmarking SQL

When I work on improving database performance, I follow three simple steps: measure, measure and measure. Basic tool for that is simple timer. In SQL Server syntax that would read something like this:

CHECKPOINT; DBCC DROPCLEANBUFFERS;
DECLARE @StartTime DATETIME = GETDATE();

SELECT SomeField1, SomeField2 FROM SomeTable WHERE (SomeFieldN='Something');

SELECT [Duration] =  DATEDIFF(ms, @StartTime, GETDATE());

Although code is pretty much straightforward, first line requires some explanation.

SQL Server is pretty smart tool with lot of caching going around and testing on cached data is not something that gives consistent results. CHECKPOINT statement ensures that all dirty pages are written to disk and DBCC DROPCLEANBUFFERS ensures that cache is cleaned. Those two statements together basically force database to be in worst-case-scenario for performance but in best state for testing.

Of course, not all decisions can be made by this simplest of all tests. However, it will serve as pretty good rule of a thumb.