Thursday, February 28, 2008

Fragmentation Analysis Report in Vista

For those who have been using windows for a while, are probally use to the old defragmentation tool which provided feedback about the current fragmentation of your drives via a graphical UI, and via a report which provided a gauge as to how fragmented your system is.

Microsoft made some good improvements to the disk defragmenter in Vista. First they have setup a schedule by default for the disk defragmentation to run. This weekly defragmentation is a huge step in keeping our disks nice and tidy.

Because it is now automated by defaulted, they also gutted the interface making it very simple. Gone are the color graphs and if you really want those graphs I suggest finding a third party tool which might have them. They also removed the option to get the fragmentation analysis report.

Not trusting Microsoft to properly implement something, I went looking for the analysis report to see how effective they have been defraging my drives (particulary since I am using a laptop which I usually power off).

What I found was that the command line tool defrag was still around and can provide the analysis report. In order to get it run the following command from a command prompt:
defrag c: -a -v

This will spit out a simillar analysis report. The only difference seems to be it doesn't list the most fragmented files.

From what I can tell Microsoft got this feature right. Without me doing anything my disk is has a 1% file fragmentation which considering my disks back on XP would sit around 9% after defraging the drive is a preety good thing.

Happy Defraging!


Wednesday, February 27, 2008

Fixing send to compressed zip in Vista

Today I was being my usual foolish self, and I went to the properties of the Send to Compressed folder FYI in Vista this is stored in:

I then changed the default program that is used, which essentially destroyed my ability to send right a compressed folder. I found it interesting that the command dropped off of my send to menu.

After digging around google and not finding anything to help me, I decided to scour the registry myself. I assume you know how to edit the registry otherwise you shouldn't be messing with the registry.

In the HKEY_CURRENT_USER hive is a section which stores the file associations that a user has made. The Send to Compressed file is stored as .ZFSendToTarget and is located here:

There are a couple keys here which are important:

  • OpenWithList - This drives the Open With menu you see when you right click a file. The values it contains are all the options in the Open With menu.

  • OpenWithProgIds - I am not positive on the role of this, but it contains a CLSID which points to the zipFldr.dll Search the registry for the key here and you will see what I mean. Based on how modifying the keys affected my system this looks like a default as long as the next key has not been created

  • UserChoice - This contains ProgId for the application I choose to use for this file type

  • Resolving this issue was very simple. Delete the UserChoice key and your Send to Compressed File option will again work.

    Hopefully your not as foolish as I was and change this in the first place, but in case you do this is a really easy fix.


    Friday, February 22, 2008

    Replacing mailSettings with Web Deployment Projects

    Up until this morning, I've been able to avoid deciding how to handle environment specific settings for a new application I am working on. By using the hosts file, I was able to create a logical name for my SQL server for example which I could replicate accross my environments. This worked fine until this morning when I added email sending capabilities into the web application.

    I decided to go and implement web deployment projects which provide a way to replace portions of the configuration files. I set everything up and then following along with this article from Microsoft.

    I click build and I get the following error: Error 106 web.config(1): error WDP00002: missing section

    It turns out WDP's configuration replacement tool cannot replace SectionGroups. It can only replace sections. Both System.Net and mailSettings are SectionGroups and thus cannot be replaced out.

    If you want to replace the mailSettings you will need to target the smtp node so you'll want to use the following settings:<your config file>

    Wednesday, February 20, 2008


    I am going to try and keep my personal life out of this blog, but last night I took my wife to see Wicked for the second time. It is a really great show and I recommend anyone who has ever seen the Wizard of Oz (and if you've never seen the Wizard of Oz then I wonder what deep dark hole you crawled out of) to go see it.


    Thursday, February 14, 2008

    Javascript, Scope Context ohh my


    So my last post started to dive into the scope, and context around javascript exection. I have since come accross a really good post by Mike West. This article showed another solution to the issue of loosing scope.

    I ran into a problem where I had a javascript object and I wanted a functon in the object to be called. I am a big fan of composing my methods into smaller methods, so like many functions I write this function made calls to other functions that were within in the same object. So for example we had something like:
    function world(){    
      //do something    

    When I attached the handleClick function to the event handler of a button for example. I would loose the ability to call the rotate method. This was due to the context "this" (See the article I referenced above for a good explanation).

    The soltion Mike West highlighted (which appears was borrowed out of prototype Javascript which is referenced in his article). Is to extend the function object itself. We can define a bind function which allows us to change the call context prior to calling our method.

    Function.prototype.bind = function(obj) { 
     var method = this, temp = function() { 
      return method.apply(obj, arguments); 
     return temp; 

    Using this solution is extremly easy. You can simply say object.event=myWorld.handleClick.bind(myWorld);

    Javascript's setInterval / setTimeout

    Kicking off asynchronous tasks is a common problem in programing languages, and while I have become very accostumed to managing threads and using timers in .Net, I found that two of the mechanism in Javascript for executing code asynchronously at specified intervals to have some odd pecularites.

    If you google setInterval and setTimeout, you will learn that these are two methods that can be used delay execution of code by a certain number of milliseconds. setInterval will execute some javascript code every x milliseconds. I am going to focus on setTimeout (setInterval has the exact same semantics).

    setTimeout takes two parameters, the first is either a string or a function pointer, and the second is an integer which is the number of milliseconds to wait before executing the code. For example setTimeout("alert('hello world')",10000); Will cause an alert box to be displayed after 10 seconds.

    While this might be useful in some cases the more powerful form is to pass a function pointer to be executed. There are a couple key points to keep in mind when using the function pointers:

    • First is that you are to pass a reference to a function so the following will not work as expected:

      This will result in the code being executiung immediatley. You will need to instead use: setTimeout(myObj.sayHello,5000);

    • Since you are limited to using a function pointer you cannot pass any arguments (There is a workaround for firefox but it is not supported in ie).

    The question then becomes how do you pass in arguments. You might be tempted to use the string overload; however, when setTimeout evaluates a string the current context becomes window. This causes all references to this to evaluate to the window object.

    To get around this you can create a javascript object which is nothing more then a function. Imagine the following code

    function world(numPeople)


    this.sayHello=function(){alert("Hello to all " + this.numberofPeople + " people in the world");}


    myObj=new world(1000);

    When we run this code we should get an alert box saying hello to 1000 people; however, we get an alert indicating that this.numberofPeople is undefined. The this keyword is pointing to the window object which doesn't have a definition for numberofPeople.

    A small change to this object will make it work. And I am curious to the opinion of anyone who comes accross this blog as to if this is an ok solution.
    function world(numPeople)

    var numberofPeople=numPeople;

    alert("Hello to all " + numberofPeople + " people in the world");

    return numberofPeople;


    myObj=new world(1000);


    Here are changing the numberofPeople to a variable within the scope of the function world. This ensures that when the sayHello method is executed that the variable is still within scope; however, if you needed to also access the numberofPeople variable from outside of the world function you will need to add an accessor such as get_numberofPeople.

    Sunday, February 10, 2008

    Windows Vista 64 & Virtual CD/DVD

    So, I start a new job on Monday, at a brand new company (I am the first employee). Because of this I had to run out and buy a temporary laptop while my real one was being shipped from Dell. I ended up finding a nice deal on an HP at Compusa which is being liquidated.

    The problem I have run into is finding a virtual cd/dvd drive to load the images from MSDN for Windows Vista x64. Microsoft has a great little tool for this Virtual CD-ROM Control Panel for Windows XP. This tool sort of works on Vista but not on Vista x64 at all.

    I tried Magic ISO; however, whenever I went to open up my computer, with a drive mounted windows explorer would crash.

    I am still in search of a working tool and should I find one I will update this post. For now I am just waiting anxiously for my real laptop with good old WindowsXP on it.

    My message to Microsoft would be that if you release new OS's you should release updated versions of your tools. If you want to drive adoption of Vista you do need to ensure the tools are available either from you or from a third party.