Jun 092010
 

Blue screen of death (BSOD) errors may drive people crazy, but they really are useful in pinpointing the root cause of the problem preventing the computer from starting up. Beneath that obscurity, there is enough hidden information to help fix nagging errors. However one dreaded BSOD which still is a tricky customer is the 7B or INACCESSIBLE_BOOT_DEVICE error. Its causes can be many and each has its own solution without a guarantee of success.

So yesterday, when my Vista laptop was stuck in a restart loop with this error, I knew it was going to be a long night. After trying a million different things, I finally gave up at 5 AM, too tired to carry on. Today, after even more endless rounds of restarts and head banging, it finally got resolved and I saw the magical Vista login screen. 🙂 I listed down a few of the steps I followed – might be useful for others haunted by this deathly error.

  • Pinpoint the cause: Doctors don’t charge you for prescribing the right medicine, they charge you for getting the diagnosis right. Once that part is solved, the cure just falls into place. Its the same case with BSODs. Google/Bing can help you out here in finding the documentation for each error which can help you find out what is exactly wrong. However some, like the 7B are different. It can be caused by hardware failures, SATA/IDE compatibility issues, wrong RAID settings, boot sector issues among others. The trick is to isolate each of them one by one.
  • Check what changed: Errors usually occur due to something that has changed recently. Remembering any settings/configurations/hardware changes you recently did can go a long way in helping us pinpoint the cause. In my case I had made two changes, one was turning off DEP to speed up large file copying in Vista and forgetting to unplug my external hard drive while rebooting. Both changes effect the Vista BCD (Boot configuration data).
  • Check the hardware: If there is something a few months in tech support have taught me, its the golden rule that no amount of software troubleshooting can fix a hardware error. Always run your diagnostics first. Dell comes with a range of built in utilities to do just that. The Preliminary PSA tests can be started by pressing F12 while windows boots and choosing Diagnostics. It first runs some basic hardware and memory tests and then gives more options. For 7B, the hard drive is a likely culprit so run all the tests on it to make sure. Also run chkdsk  /f which scans for any bad sectors and marks them to be avoided later. Bad sectors in the boot record can also lead to the error.
  • Check the BIOS: After the hardware, the BIOS is also a major cause of 7B errors. It could be a SATA mode or RAID settings issue. Try changing the settings for SATA operations from AHCI to ATA (could be named differently in your BIOS). If it doesn’t work, change them right back. This article gives a description of the issue and resolution.
  • Give automated repair options a shot: There are two automated recovery options in Vista – one is the startup repair and the other is system restore. Experienced users usually look down on automated options as being reserved for the dummies. True they don’t work most of the time, but its still worth a shot. The next point will elaborate on how to get the automated repair options
  • Use Windows Recovery Environment: WinRE is a set of very useful tools which is bundled in vista. It gives you access to System Restore, Memory diagnostics, PC Restore and command prompt. WinRE can be started from the local computer by pressing F8 during boot and choosing Repair Computer in the menu. It can also be started from the Vista DVD , by booting into it and clicking Repair on the installation screen. The command prompt can be used to launch many boot utilities along with regedit.
  • BCDEdit and BootRec: Both of these are utulities which can be used to fix the boot record of Vista which can get corrupted due to a number of reasons, one of them being installation of another OS in the system. Bootrec has four options – fixboot, fixMBR, RebuildBCD and ScanOS. Their functions taken from this support article are given for easy reference. In my case the ScanOS wasnt able to identify any OS installations on the drives. So basically, the Boot record was toast and had to be rebuilt manually. Given the alternative of a format and fresh install, this option sounded like lesser work.
/FixMbr
The /FixMbr option writes a Windows 7 or Windows Vista-compatible MBR to the system partition. This option does not overwrite the existing partition table. Use this option when you must resolve MBR corruption issues, or when you have to remove non-standard code from the MBR.
 
/FixBoot
The /FixBoot option writes a new boot sector to the system partition by using a boot sector that is compatible with Windows Vista or Windows 7. Use this option if one of the following conditions is true:
The boot sector has been replaced with a non-standard Windows Vista or Windows 7 boot sector.
The boot sector is damaged.
An earlier Windows operating system has been installed after Windows Vista or Windows 7 was installed. In this scenario, the computer starts by using Windows NT Loader (NTLDR) instead of Windows Boot Manager (Bootmgr.exe).
 
/ScanOs
The /ScanOs option scans all disks for installations that are compatible with Windows Vista or Windows 7. Additionally, this option displays the entries that are currently not in the BCD store. Use this option when there are Windows Vista or Windows 7 installations that the Boot Manager menu does not list.
 
/RebuildBcd
The /RebuildBcd option scans all disks for installations that are compatible with Windows Vista or Windows 7. Additionally, this option lets you select the installations that you want to add to the BCD store. Use this option when you must completely rebuild the BCD.
  • Rebuilding the BCD: After stumbling on a lot of dead ends to repair the boot sector. I finally found an article which explains how to do so. I used the following commands in the article to manually create a new BCD entry and assign it the path of the Windows directory.  Then the new entry is made default and the old one deleted.
bootrec.exe /fixmbr
x:\boot\bootsect.exe /nt60 all /force
Now we get rid of the old BCD registry, and create a new one instead.
Note: We're assuming that the boot drive is drive C: below. If your computer is configured differently, be sure to use the appropriate drive letter here instead.
 
del C:\boot\bcd
bcdedit /createstore c:\boot\bcd.temp
bcdedit.exe /store c:\boot\bcd.temp /create {bootmgr} /d "Windows Boot Manager"
bcdedit.exe /import c:\boot\bcd.temp
bcdedit.exe /set {bootmgr} device partition=C:
bcdedit.exe /timeout 10
del c:\boot\bcd.temp
Now we have a clean, working Vista bootloader. But we need to add a Vista entry to it:
 
bcdedit.exe /create /d "Windows Vista" /application osloader
bcdedit.exe should return a message with a GUID for the newly-created entry, something like this:
The entry {c0dfc4fa-cb21-11dc-81bf-005056c00008} was successfully created.
 
You'll need to use the value that bcdedit.exe returned for you below, along with the drive letter for the drive that Windows Vista is installed to:
 
bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} device partition=C:
bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} osdevice partition=C:
bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} path \Windows\system32\winload.exe
bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} systemroot \Windows
 
bcdedit.exe /displayorder {c0dfc4fa-cb21-11dc-81bf-005056c00008}
bcdedit.exe /default {c0dfc4fa-cb21-11dc-81bf-005056c00008}

This finally fixed my problem, and hopefully yours too!! Even if it didn’t, I hope there was enough information in the post to point you in the right direction.

Dec 152009
 

I am not usually fazed by Windows error messages, facing tons of them all these years. But with Vista, microsoft had promised an end to the infamous Blue Screen of death cryptic error message. But today when I woke my laptop from its slumber, I faced an even more puzzling situation – the Blank Screen of Death.

Its different from the Black Screen of Death  in Windows  7 as it eventually lets you inside if you press Ctrl – Alt – Del and run the explorer.exe task. But once inside Windows, none of the services were running. I tried to run the reliability monitor and the Event Log to identify what caused this strange error, but the services associated with them were not running either. Any attempt to start them failed as the option to the start them were not available in the management console.

The usual reboot didn’t work either. I tried System Restore as well, but to no avail. A quick google search suggested the Startup repair from the Vista disk, but I was too lazy to locate my Vista disk. Just as a last resort, I tried to startup the system in Safe Mode – going back to the Windows Me days where the safe mode was the only thing that worked. The Safe mode had the same issues with the services being stopped. But before shutting down, I made the last ditch attempt of running the System Restore from the Safe mode and lo and behold – it worked.

So a synopsis of the solution that worked for me.  Restart the system in Safe Mode and run the System Restore to restore the system to any system scheduled checkpoint.

If it doesnt work for you, try the Repair option from the Windows Vista disk that came with your system.

Nov 302009
 

I didn’t know this was possible until a few days back when a user asked about it on one of the MSDN forums. The query was on how to integrate Winforms and WPF i.e. how to display WPF user controls in Winform application. This feature can be extremely useful because some elements and effects which are easy in WPF can make you sweat a lot in Winforms.

Also this might be useful when you are eventually looking to migrate your application GUI to WPF. So when you are able to create resuable user controls and reuse them in Winforms, it will allow you to port all your winform user controls to WPF one at a time.

The control in Winforms which can do this is the ElementHost which resides in the WindowsFormsIntegration assembly. The ElementHost is responsible for loading the WPF control and painting it. Lets see how to do it. First we will create a user control in WPF. The markup is

<UserControl x:Class="WpfApplication1.SampleWPF"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">
    <Grid>
        <StackPanel Margin="12,91,12,30">

            <TextBlock HorizontalAlignment="Center" Text="Sample WPF Control"
                       FontSize="20"
                       FontFamily="Verdana"
                       />

            <Button Name="btnClick" Click="btnClick_Click" Content="Click ME" HorizontalAlignment="Stretch" />
        </StackPanel>
    </Grid>
</UserControl>

Nothing really, just a StackPanel inside the grid with a TextBlock and a Button. Just to see a WPF Event we hookup an event handler to the Button.

public partial class SampleWPF : UserControl
{
    public SampleWPF()
    {
        InitializeComponent();
    }

    private void btnClick_Click(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("WPF says Hello");
    }
}

Now that the WPF part is done, all we need to do is create a Winform Host for this user control. Create a new Winform project and add a reference to the following dlls:-

  • PresentationCore.dll
  • PresentationFramework.dll
  • WindowsBase.dll
  • WindowsFormsIntegration.dll
  • Your WPF DLL which you just created.

Now just to show interoperability between WPF and Winforms, drag a Winforms label and button and hook an event handler to it. In the Form Load handler we create an ElementHost. Since we added the WPF control’s assembly reference, we can create an object of the WPF user control. Of course we cant add the control to the Form’s control collection since the Form object has no idea how to draw the WPF control. This is where the ElementHost control comes in. The ElementHost takes in the usercontrol as its child control and is added to the Winfrom. The code is:-

private void Form1_Load(object sender, EventArgs e)
{
    ElementHost _host = new ElementHost();
    _host.Dock = DockStyle.Fill;
    WpfApplication1.SampleWPF _wpfUserControl = new WpfApplication1.SampleWPF();
    _host.Child = _wpfUserControl;
    this.Controls.Add(_host);
}

private void btnWinClick_Click(object sender, EventArgs e)
{
    MessageBox.Show("Windows Says Hello");
}

And this works great. Both the events for the WPF user control and the Winform controls work here. Some screenshots below:-


WinForm

wpfclick

winclick

The magic here is done by ElementHost and another class AvalonAdapter. Avalon as you would recall was WPF’s code name in its early stages of development. The Avalon Adapter is responsible for drawing the WPF application to the Windows form. The hWndSource object is responsible for creating the hWnd for the window. Using this you can actually make WPF interop with Win32 applications as well.

This method is not without its limitations though, you cant pretty much do anything which is possible with WPF, for e.g transparency

Nov 292009
 

In the last post, we saw how the Message Loop in Windows works, with Windows constantly getting messages from the various events and dispatching them to correct window procedures. The Window Procedure then takes the message and it is responsible for handling the event. This handling of the message is done in the callback method WndProc. Most of them times the default processing is done by calling the DefWindowProc method, but it is left to the procedure which can override any messages it wants.

Since its message based all windows can talk to each other using these messages and pass commands. An extremely useful feature which means your .NET application can communicate with your C application and send it commands as well. I tried to get a C application to display a message box triggered from a .NET application and then bring it to top.

First we need to write the C application to display a simple window which has a Hello World message. I will post just the relevant code here.

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
 
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc ;
	PAINTSTRUCT ps ;
	RECT rect ;
	switch (message)
	{
		case WM_PAINT:
			hdc = BeginPaint (hwnd, &amp;ps) ;
			GetClientRect (hwnd, &amp;rect) ;
			DrawText (hdc, TEXT ("Hello World"), -1, &amp;rect,
			DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
			EndPaint (hwnd, &amp;ps) ;
			return 0 ;
		case WM_USER:
			MessageBox (NULL, TEXT (".NET App Says Hello"), TEXT(".NET"), 0) ;
			return 0 ;
		case WM_DESTROY:
			PostQuitMessage (0) ;
			return 0 ;
	}
	return DefWindowProc (hwnd, message, wParam, lParam) ;
}

Along with the rest of the plumbing code, this will draw a window on the screen with the text “Hello World” written in the center. It behaves like any other normal window where you can resize it, maximize or minimize it etcetera.

CApplicationWindow

If you see in the WndProc code there are three messages being intercepted. All others will be handled as default. One is the WM_PAINT, which is responsible for drawing the window and the text written in the center. The last one is WM_DESTROY which is called when the user closes the window. The WM_USER is of our interest. All we did is call another API function MessageBox which displays a message box with the text “.NET App says Hello” and the title “.NET”. Now the idea is to call this message from our .NET application

In our .NET Application we will pass the message to the Hello World window and make it the Active Window. To do this, a handle to the window is needed. Handles are nothing but an integer which Windows (OS) uses to uniquely identify each window. Think of it as something like a pointer to the window we want to modify or retrieve information about. In .NET the IntPtr class can be used in place of a Handle to a window. From .NET 2.0 onwards, the SafeHandle can be used to do the same thing and is more reliable. Getting a handle is done through the FindWindow API call. Then using the handle, the window is sent a message and brought to the foreground. The Pinvoke declarations are:-

[DllImport("user32.dll", SetLastError = true)]
   static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

   [DllImport("user32.dll")]
   [return: MarshalAs(UnmanagedType.Bool)]
   static extern bool SetForegroundWindow(IntPtr hWnd);

   [DllImport("user32.dll", CharSet = CharSet.Auto)]
   static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

As you can see the FindWindow takes in strings the class name and the Window name. The class name and the Window name are used while calling the RegisterClass WIN32 function. Since we do this manually for C we know these values. There is no way in .NET to get the WIN 32 class name for a window. We need to use the GetClassName function for doing that.

So in .NET we first get the IntPtr handle to the C application window, and then check if its a valid window handle. If so we send a message WM_USER to the application. This WM_USER is defined as a constant in .NET. “C” however is aware of all these constants. After sending the WM_USER , we set the window as foreground by calling the SetForegroundWindow and passing the handle to it. The code is given below.

public const int WM_USER = 0X400;
static void Main(string[] args)
{
    IntPtr _CWindowHandle = FindWindow("HelloWin", "The Hello Program");

    if (_CWindowHandle.ToInt32() != 0)
    {
        SendMessage(_CWindowHandle, WM_USER, IntPtr.Zero, IntPtr.Zero);

        SetForegroundWindow(_CWindowHandle);
    }
}

So run the C program first and leave it as such. Now run the .NET application and it will work. The message box (written in the C Program) will be triggered from the .NET application and once you click on it, the window will automatically come to the foreground. Of course this is just a trivial functionality that we just implemented. A lot more complex things can be achieved once you start playing around with it.

MessageBox

SetForegroundWindow

Nov 062009
 

As Tech Days drew to a close today, we were treated to a preview of Futuristic technologies being developed currently at Redmond and… you guessed it Windows 7 and Bing. You have to appreciate Microsoft for the way it believes in its products and promotes them. They just threw everything they had on us. It was called a demo extravaganza but it turned out to be a marketing extravaganza. Though I have to admit, it was the first time that I saw bing in action.

Microsoft seems to have realized that a Search engine, no matter how brilliant can never defeat Google. Why would anyone switch from Google for keyword based search which is anyway very good at Google. Hence the strategy of promoting Bing as a decision making engine, which helps you in more ways than just returning the pages that have your queried keywords in them. I feel that both Microsoft and Google are going opposite ways now, and only when we have the benefit of hindsight, we would be able to tell who had the better strategy.

What I mean by opposite way, is that while Google tries to get users to leave its website as soon as possible to see the first result returned, Microsoft wants to engage users to be on their site to make the entire decision there before finally going to the manufacturer site just to buy the product. Now this scenario makes more sense while choosing products to buy, what about other scenarios. What if I searched for source code on the net, or for downloads. How would Visual search help me in doing that.  I decided to try it out though. Some features were quite cool.

One more noticeable question was when the person from Microsoft asked us how many lines of code Windows 7 had. I quipped “You would have Windows open source for us to know that”, to which he laughed and called it a “good” idea. Yeah right, like thats ever going to happen.  He said that NT had 43 million lines of code while Vista had 33 million. Winodws 7 has been written in just 17 million lines of code. Though Wikipedia disagrees and reports drastically different figures, Microsoft would surely know better about their properietary software better than wikipedia does.

The session ended with a demo of photosynth, a tool which analyzes several photos of a location from different angles to form a 3D view of the place. Quite neat I must say.

Nov 052009
 

In my last blog, I wrote how Windows Azure could benefit the customer by decoupling the application from the infrastructure and allowing the customer to concentrate on his application logic alone. So this time I decided to blog about the technical implementation of Windows Azure. I am new to this, so please bear with me if its not detailed enough Here is a diagram showing the architecture of how Azure works azure1 As you can see in the diagram, Windows Azure separates the application from the underlying hardware. There is a fabric controller which is an intermediary between the application and the hardware. This fabric controller internally uses Services to perform many activities like Load Balancing. The Fabric also monitors the state of the servers i.e. in case a Server fails, it internally switches the VM to another server in real time. i.e. no downtime is involved. The servers installed in the data center are not high end machines. They have medium capacity processing power and no RAID setup

One more important component of Azure is the Storage Services. Storage in Azure is done in three forms – blobs, tables and queue. Why we need this kind of storage is that the storage needs to be available to be copied to multiple VMs on the fly. The simplest way to store data would be in the form of blobs going to a maximum of 50 GB. However, we may need a more structured data handling mechanism at time. Here is where tables and queues come in. Tables are hierarchical data structures and not relational ones. They are indexed tables which are queried by LINQ rather than SQL. These tables can reside in several servers at the same time.  Also to ensure data is not corrupted, this data is stored in three different locations. This more than compensates for absence of RAID setup in the servers.

Queues are somewhat different than both than blobs and tables that they are uses as a means of communication. Suppose you have an application for downloading and playing MP3 songs. For this, any request for a particular song would be stored in a queue. This will be read by a server and processed and removed from the queue. The queue system decouples the front end from the back end and as long as both are able to understand and process queue messages, they can work irrespective of the technology.

Well thats it for today. More to follow about Windows Azure services.

Nov 042009
 

Though Azure has been a “hot” word for nearly an year now, I didnt really look into it much. Sure everyone was talking about Cloud Computing and how it would define the web in the years to come, but there was no motivation for me to go and dive head first into Azure. That motivation came today at the Tech Days event at a Session on Azure. So I decided to write a blog on how Azure would be beneficial from a customer’s point of view. Will follow it up with a post on the technical details.

azure

Azure is Microsoft’s very own Cloud Computing platform. It will allow organizations to focus their attention solely on their business purposes rather than IT centric points like capacity, load balancing etc. So the only activity for maintaining an application would be in development and testing, and Azure would do the rest of the magic for you. This means lesser resources would be required for maintaining an application and you wont  require a full time Support guy on call just in case something goes wrong.

So how does this work? Microsoft has many data centers across US and is in the process of opening many more. These data centers house tens of thousands of servers, which are used for virtualization and creating VMs where the client application is hosted on. Each VM is a system with a 2 Ghz processor and 250GB disk space, which acts as the server for your application. Suppose there is a sudden surge in traffic and the application VM is getting overloaded, the client can immediately request for another VM instance (it costs extra money of course). In real time, a new VM instance would be created and the application be copied to it and with that your site has instant extra capacity, with absolutely no downtime at all!!! So no more need for planning for that sudden festive season rush to your site and paying for the extra hardware all year long. Azure’s pay as you go model is extremely economical and would work out to be far more cheaper than what most companies currently spend on their IT Infrastructure.

The first thought that came to my mind was whether organizations would be able to host Azure on their own datacenters rather than relying on Microsoft to provide hosting. But Alas, it is not to be. Steven Martin wrote on his blog quite some time back “We don’t envision something on our price list called ‘Windows Azure’ that is sold for on-premises deployment”. I am hoping that this is temporary, till Azure is stable enough to hand over a third party and some day, it would be available for on-premise development. For very large organizations, it makes a lot of sense to maintain their own data center which would be more reassuring from a security point of view. And VMs could be shared between applications. Instead of having buffer capacity for each application as in the current model, all the applications on the network could share a common buffer which could be interchanged between apps instantly.

Another issue is the permissions. On dedicated servers, we have the luxury of operating with full privileges for both Windows and IIS. On Azure, where inspite of having a separate VM, a single server could be shared for multiple applications, would the customers have the same level of control.

There are many more questions and concerns like these which need to clarified. The PDC is coming up in another 2 weeks. Lets hope there will be more clarity then.

Oct 282009
 

Microsoft is conducting a three day TechDays Event at work from November 4th to 6th. A wide range of topics will be covered including latest Microsoft technologies like Windows 7, Visual Studio TS 2010, Exchange Server 2010, Sharepoint 2010, Silverlight and Azure among others.

techdays-2009_thumb[1]

I immediately nominated myself for it lest the number of slots get over. There are also separate tracks for developers, architects and IT professionals, totally having more than 20 sessions each day. I hope we get to choose the sessions to attend rather than being tied to a particular track as this would make the whole event more flexible.

Will post whatever new I learn there!!!

Oct 222009
 
Windows 7

Windows 7

Microsoft has finally announed the pricing of retail versions of its newest operating system Windows 7 in India. The software giant has kept the price 20% lower than other regions in an attempt to tackle piracy.

There is bad news though, because Microsoft has a tax dispute with Indian customs over the new tax rules for imported Software, the release of Windows 7 is delayed till this dispute is resolved.

A basic home version of Windows 7, available only in emerging countries such as India, is priced at Rs 5,899, excluding taxes, while the high-end version, Windows 7  Ultimate, will cost Rs11,799. In the US, the high-end version costs $320 (Rs 15,000).

But this announcement is not that significant since more than 90% of the Windows software sold in India is bundled with PCs and laptops. These versions are what are called as OEM (Original Equipment manufacturers) version. Microsoft is yet to announce its pricing for this segment.

Since my laptop is made by an OEM, I am one of those in the limbo without any news about the upgrade. Though the retail version is an option, its cost is highly unattractive. OEM versions of Windows are many times cheaper than retail versions, since these are not supported by Microsoft rather its the OEM’s responsibility to do.

As always, will post in case of any updates.

Oct 212009
 

There’s just one day to go for the official Windows 7 launch in India, but Microsoft has still kept the pricing in India under wraps. Maybe its a strategy to increase the curiosity levels. If so, it sure is working.

windows7box-1024x401

I have been trying to find the upgrade cost for Windows Vista Home premium to Win 7 for the OEM version, but no one seems to have a clue. The prices for the US versions were announced way back. Amazon.com is offering the retail upgrade at $119.99 and the full packaged version at $199.99. These prices for the Home premium edition.

Amazon- win7

Amazon- win7upgrade

However OEM versions are traditionally cheaper since they are not supported by Microsoft and the OEM (Original equipment manufacturer) is responsible for the support.  Another retailer NewEgg.com is offering the home premium at $109.99 at a significant discount to the packaged version. I was not able to find the cost for an OEM upgrade here.

Newegg

To get rid of the confusion, I called up Dell, my OEM to ask whether they have any idea but they were equally clueless. One TSR told me that the cost of the upgrade might be 2-3K, which is fair enough I guess. I plan on pestering Dell again tomorrow for the price. Will post any updates

EDIT: 10/22/2009 12:18PM IST:  Called Dell. Aparently they dont know anything about paid OEM upgrades yet.  They flatly told me that I am not eligible for the free upgrade, which I already know. any information. anyone??