Hackviking.com He killed Chuck Norris, he ruled dancing so he took up a new hobby…

20Oct/140

How to change from IDE, ATA or RAID to AHCI

Dell Bios ATA Settings

I decided to break the RAID1 on my Dell M6500 so I could run Microsoft Server 2012 R2 along with my Windows 7 installation. When the RAID was deleted I thought it would be best to switch my SATA controller over to AHCI since I'm running two Corsair Force GT SSD drives. After changing to AHCI the computer blue screens during boot. I have done it several times before but not often enough to remember what needs to be enabled. This behavior is documented in Microsoft KB922976 (Error message occurs after you change the SATA mode of the boot drive) with automatic registry fix and all. However this is not the complete solution for all situations.

According to the KB you need to enable loading of the AHCI driver, a no brainier! And also enable the Intel AHCI controller driver. But what is not included in the KB article is that the ATAPI driver also needs to be enabled for it to work. If you try to change from ATA to AHCI it is already enabled, if your computer booted with the ATA setting.

So according to the KB you should set these two registry keys to "0":

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Msahci\Start
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\IastorV\Start

But you should also check that this one is set to "0":

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\atapi\Start

You can also run these commands instead:

REG ADD HKLM\System\CurrentControlSet\Services\msahci /v Start /d 0 /f /t REG_DWORD
REG ADD HKLM\System\CurrentControlSet\Services\IastorV /v Start /d 0 /f /t REG_DWORD
REG ADD HKLM\System\CurrentControlSet\Services\atapi /v Start /d 0 /f /t REG_DWORD

Now your computer will start without the blue screen!

Filed under: Windows No Comments
18Jun/140

Hyper-V – accessing info about physical machine from guest VM

More then once I have run into the problem of not knowing on witch physical server a Hyper-V hosted server is running. Getting RDP access to a clients system and then needing help from SAN or Network teams, there first question: "What physical machine is the host running on?". Without access to the physical servers or System Manager it's hard to know. You could probably figure it out from assigned IP-addresses but there is a quicker way if the Hyper-V Integration Services are installed.

This registry key: HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters

It contains the following information:

  • HostName
  • PhysicalHostName
  • PhysicalHostNameFullyQualified
  • VirtualMachineName
  • And also additional info about server version etc.

You can also run this from the CMD:
reg query "HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters" /v PhysicalHostName

If you have remote access:
reg query "\\<machine>\HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters" /v PhysicalHostName

Ofcourse you can replace the "PhysicalHostName" with any of the above values!

16Jan/140

.Net C#: Webbrowser control print line break

I was updating an old project for a client today. I needed to print a simple list and figured that the easiest way should be to format the data in HTML. Most developers out there has built webpages now days and we all know that it is a quick way to format the information and print it. So after a quick creation of the HTML i found an article named "Displaying custom HTML in WebBrowser control" by Gunnar Peipman. So easy enough to print the custom HTML from the control, based on Gunnar's article I came up with this code:

WebBrowser webPrint = new WebBrowser();
webPrint.Navigate("about:blank");

if (webPrint.Document != null) { 
    webPrint.Document.Write(string.Empty);
}
webPrint.DocumentText = printHTML.ToString();
webPrint.DocumentCompleted += webPrint_DocumentCompleted; 

void webPrint_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { 
    WebBrowser webPrint = (WebBrowser)sender; 
    webPrint.ShowPrintDialog(); 
}

If you don't use the "DocumentComplete" event handler your printout will be blank. In the print I used a basic HTML table to show the data with rows like this:

<table cellpadding="3" style="width:100%">
<tr style="color:White;background-color:Black;font-weight:bold;"><td>Box ID</td><td>Gång</td><td>Hylla</td><td>Nivå</td><td>Nåbar från golvet</td></tr>
<tr><td>10346</td><td>AB</td><td>3</td><td>F</td><td>True</td></tr>
<tr><td>10294</td><td>AB</td><td>3</td><td>D</td><td>True</td></tr>
<tr><td>10296</td><td>AB</td><td>3</td><td>C</td><td>True</td></tr>
<tr><td>10298</td><td>AB</td><td>3</td><td>C</td><td>True</td></tr>
<tr><td>10300</td><td>AB</td><td>3</td><td>B</td><td>True</td></tr>
<tr><td>10302</td><td>AB</td><td>3</td><td>B</td><td>True</td></tr>

When printing data that took up several pages I ended up with this:

pagebreak error

The data was cut of at the line breaks. I Googled a lot and found a few suggestions about css "page-break.." but they didn't have any effect on the webbrowser control print layout. Finally I found a simple soulition, just add a bland column to the left of the table and the line break works. Like this:

<table cellpadding="3" style="width:100%">
<tr style="color:White;background-color:Black;font-weight:bold;"><td> </td><td>Box ID</td><td>Gång</td><td>Hylla</td><td>Nivå</td><td>Nåbar från golvet</td></tr>
<tr><td> </td><td>10346</td><td>AB</td><td>3</td><td>F</td><td>True</td></tr>
<tr><td> </td><td>10294</td><td>AB</td><td>3</td><td>D</td><td>True</td></tr>
<tr><td> </td><td>10296</td><td>AB</td><td>3</td><td>C</td><td>True</td></tr>
<tr><td> </td><td>10298</td><td>AB</td><td>3</td><td>C</td><td>True</td></tr>
<tr><td> </td><td>10300</td><td>AB</td><td>3</td><td>B</td><td>True</td></tr>
<tr><td> </td><td>10302</td><td>AB</td><td>3</td><td>B</td><td>True</td></tr>
<tr><td> </td><td>10382</td><td>AB</td><td>4</td><td>F</td><td>True</td></tr>

Then the printout looked like this:

pagebreak fix

29Oct/130

KC Host Editor a blast from the past

Back in 2009 I did a lot of web development and that usually results in changing around the Windows host file all the time. Back then I used Windows Vista for windows development and wrote a quick sidebar gadget that can view, edit and temporarily comment out entries in your host file. It runs on Windows 7 as well if you unzip it and put the KCHostEditor.gadget folder into: %USERPROFILE%\AppData\Local\Microsoft\Windows Sidebar\Gadgets

Then you can just right click on the desktop an select "Gadgets" and add it. Just tried it out before running of so I'm not sure if it works for editing, I remember that I had to be admin on the machine. The machine I'm on now just gives me standard user, for now.... ;) But try it out if you like and if you want to do your own gadget refer to this guide:  http://msdn.microsoft.com/en-us/library/windows/desktop/bb456468(v=vs.85).aspx

22Oct/110

Windows startup error

Worked late last night, on a friday I know! One of my laptops, an XPS M1530, have been making a strange noise. The speaker locks it self in some strange scream. Sometimes I was able to get it to shut up by tapping on it but other times I had to connect headphones to get it to shut up. Last night I was tired of it so after a did the shutdown I took it apart and ripped out the broken speaker and cut out the cables. Then I put it all together again and tried to start the computer. My entire hard drive is encrypted with True Crypt and I also have a hidden operating system on the machine (both win 7 x64). On start up I got the password screen for True Crypt and entered my password for the decoy system and got this error:

Error:  error no bootable partition found

I goggled a bit and didn't find anything useful. I realized it probably was the boot properties that was messed up but none of the tools I had could access the disk because it was encrypted. So I did have the recovery cd created by True Crypt so I started it up and decrypted the entire system. Then i restored the original boot loader and tried a reboot.

Missing operating system

So I only got a new error message instead. Google didn't give me much more then that I should use the windows install cd to repair it. I have been working with windows for a long time and I don't have any good experiences with Microsoft repairs. So I didn't want to do some universal end user fix that would f*ck up my system. I booted from the windows dvd with hope of a command prompt. When I selected "Repair my system" it couldn't find my system but I could read the disk from the prompt. So I took the disk out of the computer and hooked it up to my other laptop and activated the C:\ drive of the decoy system. Now the repair function of the Windows 7 install DVD could see the installation. I got a dialog that told my that my boot options was messed up and asked me if I wanted to repair them and reboot. Yes please that would be lovely! Did it boot, of course not!

But I got even a new error! Just a blank black screen with a flashing underscore cursor. So what now? I already know that my master boot record (MBR) and probably my boot manager was broken. So I tried to boot from the Windows 7 install DVD again and issued two commands:

bootrec.exe /fixmbr
bootrec.exe /fixboot

Restarted the machine and got a new error again!
BOOTMGR is missing
But this was the first good error message so now I could really get down to fixing the issue. Started the Windows 7 installation DVD repair function again and entered the prompt. Issued the following commands:

chkdsk /r

To check for errors and "repair" them. If chkdsk finds anything the disk is usually about to fail. Really don't like when that finds anything.

Bcdedit /export C:\BCD_Backup
ren c:\boot\bcd bcd.old
Bootrec /rebuildbcd

This rebuilds the boot options for the boot manager. But this command only sacans all the disk trying to find windows installations. I couldn't see that it found anything but I could access c:\ so then i entered it manually:

bcdboot c:\windows

Then I ran bootrec again:

bootrec /fixmbr
bootrec /fixboot

Then I restarted the machine and it booted without any problem. But only my decoy system, my hidden operating system is still on a partion that looks "RAW". In my case it doesn't matter becuase I rarly used my hidden system anyway and really only created it for fun. But I think it would be possible to get the system back but I didn't try. I'm just glad that my primary system was back on track.

15Sep/090

Desktop mayhem

I have, as many others, tons of stuff on my desktop. The windows box in question is a Vista machine and I really like the fixes MS has done to the user experience since XP. But I always had trouble with all my desktop icons and my fetish to save to the desktop when it's only a temporary file, that always stays there for weeks or months when it's not so temp anymore. The biggest issue is that it's a laptop running at 1440x900px docked but not so high resolution undocked. When I have placed all my tools and stuff neatly along the sides of the screen and undock my laptop all the icons go together in a big pile in the top left corner. So when I dock again I have to tidy up all the time. Now I don't have that problem anymore! Fences really cleans up the desktop and take care of all the problems. It's good, it's easy and free!
Check it out: http://www.stardock.com/products/fences/