Clean Install With Windows 8 Upgrade Disc

When you're about to install Windows 8 using its upgrade disc, you're supposed to have an older version of Windows on the disk. Its presence will be noted and you can format the disk to make a clean install, or you can upgrade it which I prefer not to do. When you try it on a completely clean disk, Windows 8 will still install, but you won't be able to activate it due to the missing previous OS.

Top tip: If you ask nicely, it will allow your otherwise legal, purchased copy to activate.

Modify this key in the registry from 1 to 0:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ Windows\CurrentVersion\Setup\OOBE
 
MediaBootInstall = 0

Then run this from command line as Administrator:

slmgr /rearm

Reboot and you're done; you can activate your copy of Windows 8.


Macbook Hack

My little Macbook is about 6 years old now and I can't really justify its replacement yet, as it looks good and works pretty well, compared to ordinary PC laptops of its age. The performance of the Intel Core2 Duo 2.0 GHz (T7200) is quite enough for me in a secondary computer, the RAM could be faster (and bigger) and of course laptop HDDs are painfully slow, so there is room for improvement. It's hardly breaking news that you can fix some of these things with a little investment; I went a bit further in the process of modernizing.

Macbook 2,1 and some replacement parts
Macbook 2,1 and some replacement parts

What you see here is a 120GB Adata SSD, a hard disk caddy with the 500GB HDD that I put into my laptop years ago, 3GB RAM (the maximum this Macbook can handle), new CPU cooling fan, thermal paste, a new battery and an external optical drive. The "Superdrive" was about to die, so it was a good decision to replace it with a secondary HDD and the original battery was bent out of shape by now. It's best to follow these iFixit guides using proper tools, like the iFixit Pro Tech Toolkit that I ordered last year and I've been using it happily ever since. It's totally worth the money, especially for the ultimate screwdriver collection with 54 different bits.

After successfully taking off the top case (keyboard + touchpad), I took out the CPU cooler and the Superdrive and took off the heatsink to clean it, along with the CPU and the motherboard controller chip's surface, so I could add a fresh splash of thermal paste on them to improve cooling performance. The cooler itself wasn't in a too bad shape, but it's worth to get a new one on the cheap. The hard disk adapter is similarly cheap, you just have to keep in mind that this Macbook uses an IDE connector for the optical drive, so you need this one which converts SATA to IDE. Installing it is a bit harder, there are some rails and sticky stuff that you have to peel off the optical drive and put it on the caddy, to the same position, especially the Bluetooth antenna holder due to its limited cable length. Installing a primary SSD and RAM extension is easy, you don't have to take the laptop apart for that.

Macbook 2,1 internals after installing the replacement parts
Macbook 2,1 internals after installing the replacement parts

After it was all done and I put back all the parts, cables and screws, everything worked well for the first try. Well, except for the cheapo external DVD (18 bucks) that fails to work most of the time and I can't boot from any disc with it, no matter what I do. It's really a piece of junk, I won't return it only because mailing it back would cost half as much as the drive itself. I'll get a properly working optical drive when I really need it, luckily I already installed Windows 7 on the SSD (added it separately last year) and there was a Mac OS X 10.7 partition on the HDD, so these will work just fine for now. I bought a second Windows 8 Pro license that I could put onto the Macbook, but I don't think it's worth doing so, and it's good to have a Windows 7 machine around for testing.


To The Rescue

I've got sweet Adata 256GB SSD as the main drive in my workstation, but today's solid state drives are not reliable enough in my opinion. Theoretically when they die, they become a read-only flash media, but I've heard too many nightmare stories about SSDs suddenly go dead the next morning, without any chance to recover your data from it. Obviously the first thing you have to do is making frequent backups, but it's worth preparing for the total loss of the SSD (or your system HDD for that matter). What will you do until you can get it replaced? In a desktop computer there's plenty of space for my Plan B: having a bigger hard disk with a fresh (enough) copy of the SSD partitions, from which you can boot your computer and continue to work like if nothing happened.

For this you can kind of use the full system backup function in Windows, but if you ever tried it, you know about its limitations when it comes to restoring the image. It's much better to use the MiniTool Partition Wizard from which the Home Edition is free and has all the features we need to copy and activate partitions. It even lets you resize them while copying, so it's the perfect tool for the job. Also once you installed it, you can simply copy its folder from Program Files and use it in portable mode without the need to install it on any system. As it happens, it's a key feature because you shouldn't make a copy of your Windows partition while it's running, right?

I've been using a customized Windows PE (Preinstallation Environment) for these kind of rescue operations since the Vista days, it's basically a minimized version of Windows that you can boot from DVD or a USB flash drive and use for deployment, or simply for accessing and repairing a broken system. Now that I'm using Windows 8, it was time to create a new rescue media based on the new Windows PE 4.0 which now supports .Net Framework 4.5 applications and Windows PowerShell 3.0 if you set it up. It's not going to be a full blown guide to create a Windows PE image (there are dozens you can find) and I'll deal only with the latest version for Windows 8, even though the steps are roughly the same for previous versions of Windows PE. For extra content here are the official walkthrough guides for Windows 8 and for previous versions. It's also worth mentioning that I won't over-explain everything and I take no responsibility for your actions if you mess up something in your system. If you can't follow this guide, chances are you shouldn't deal with it at all.

Creating a customized Windows PE image

The first step is installing the Windows PE related bits from Windows Assessment and Deployment Kit (ADK) for Windows 8. The previous versions were called Windows AIK, search for it in the Download Center. Start the Deployment and Imaging Tools Environment as Administrator, all the build commands will be entered into this command window. Its default directory is this:

C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Deployment Tools

In this example I will use C:\WinPE as the working directory where the image will be assembled and I chose the x86 version to work on. You may create an amd64 version (apply your changes to the commands below) but it won't run 32 bit programs at all. To create an instance of the basic build, enter this command:

copype x86 C:\WinPE

It will create the C:\WinPE directory and a bunch of files in there. The Media directory is what we will put on the bootable media. The image we work on is under Sources\boot.wim and for customizing it needs to be mounted into an existing but empty directory, then it has to be unmounted to save the changes we made, back into the boot.wim file. We will use the C:\WinPE\Mount directory for this, note that it's empty. For mounting and unmounting we will use the following commands, you may create a batch file for both to make it easier to customize the image, probably you will do it several times before everything is perfect for you.

rem Mount the image into the work directory to customize
imagex /mountrw C:\WinPE\Media\Sources\boot.wim 1 C:\WinPE\Mount
 
rem Unmount and commit changes to the image
imagex /unmount /commit C:\WinPE\Mount

Once you mounted the image file, you can see its contents in the previously empty Mount directory. To avoid a lot of typing, create a batch file with the following commands that will install various packages into your image. You have to do it only once, the order of the packages do matter due to their dependency. You may check out the other packages in the WinPE_OCs directory and if you want to do custom localizations, you have to add your selected language resources beside the en-US versions. If you will use your Windows PE only in English, you are fine with this below.

rem Go into the x86 packages directory
cd /d "C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Windows Preinstallation Environment\x86\WinPE_OCs"
 
rem Windows Script Host (WSH) support
dism /image:C:\WinPE\Mount /add-package /packagepath:"WinPE-Scripting.cab"
dism /image:C:\WinPE\Mount /add-package /packagepath:"en-us\WinPE-Scripting_en-us.cab"
 
rem Windows Management Instrumentation (WMI) support
dism /image:C:\WinPE\Mount /add-package /packagepath:"WinPE-WMI.cab"
dism /image:C:\WinPE\Mount /add-package /packagepath:"en-us\WinPE-WMI_en-us.cab"
 
rem Microsoft Data Access Component (MDAC) support
dism /image:C:\WinPE\Mount /add-package /packagepath:"WinPE-MDAC.cab"
dism /image:C:\WinPE\Mount /add-package /packagepath:"en-us\WinPE-MDAC_en-us.cab"
 
rem HTML Application support
dism /image:C:\WinPE\Mount /add-package /packagepath:"WinPE-HTA.cab"
dism /image:C:\WinPE\Mount /add-package /packagepath:"en-us\WinPE-HTA_en-us.cab"
 
rem .Net Framework 4.5 (subset but most features are supported)
dism /image:C:\WinPE\Mount /add-package /packagepath:"WinPE-NetFx4.cab"
dism /image:C:\WinPE\Mount /add-package /packagepath:"en-us\WinPE-NetFx4_en-us.cab"
 
rem Windows PowerShell 3.0
dism /image:C:\WinPE\Mount /add-package /packagepath:"WinPE-PowerShell3.cab"
dism /image:C:\WinPE\Mount /add-package /packagepath:"en-us\WinPE-PowerShell3_en-us.cab"
 
rem Windows PowerShell 3.0 cmdlets
dism /image:C:\WinPE\Mount /add-package /packagepath:"WinPE-DismCmdlets.cab"
dism /image:C:\WinPE\Mount /add-package /packagepath:"en-us\WinPE-DismCmdlets_en-us.cab"
 
rem Allocated writeable memory in MB (32, 64, 128, 256, 512 - Default: 32)
dism /image:C:\WinPE\Mount /Set-ScratchSpace:512

With the same dism command you can make other changes, do localization and install optional device drivers, see the walkthrough links above but normally it's not necessary to do so.

Unmount the image (make sure absolutely nothing keeps the Mount directory open, file manager windows, command line or whatnot) and back up the boot.wim file if you want. If you made a mistake and you want to discard your changes, or there is a problem (open Mount directory for example) and the unmount command can't close your image, you should unmount it without adding /commit. Your basic Windows PE is pretty much ready but there are some other things you should add to it.

You should add ImageX which can be a very powerful tool to make backups into a single, optionally compressed wim file and restore it to the same partition or to a new disk. Copying the exe file itself may be enough, but you should just copy the contents of this directory into Windows\System32 of your image, mounted into the Mount directory:

C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Deployment Tools\x86\DISM\

Create a Tools directory in your image's root and put some tools in there, I always add Far Manager, command line tools like rar and zip, shortcut batch files, a text file with reminders of useful commands and the above mentioned Partition Wizard which will surely come handy. You may also add Raw Copy which is another tool to copy partitions and remember, you can add programs written for .Net Framework 4.0 / 4.5 too, they will run like a charm.

You should create/modify startnet.cmd in the Windows\System32 directory of your image, the commands you put in there will be executed when Windows PE opens its initial command line prompt. Beside displaying some info there with echo commands, I also do this (all between @echo on and @echo off lines) :

rem Put X:\Tools on path for easy access
set PATH=%PATH%;X:\Tools
 
rem Start Far Manager
cd \
regedit /s \Tools\Far\Far_Config.reg
start \Tools\Far\far.exe
 
rem Start Notepad with my reminder notes
start notepad.exe \Tools\readme.txt

When Windows PE is up, the image is loaded into a RAM Disk which gets the drive letter X by default. As you can see, I put the X:\Tools directory on path for quick access to the files in there, so I don't have to copy everything into the Windows directory, it's all nicely separated. Unmount the image and you're pretty much done, you just have to put it on a bootable media.

Creating a bootable Windows PE media

I recommend using a USB flash drive for this so it will be easy to change the image and add other stuff, not necessarily into the image but on the drive itself. In that case you have to figure out the assigned drive letter of your boot device in order to use them, PStart may help you out with that. To make the drive bootable, use these commands and at select disk you obviously have to enter the number of your pendrive you see in the list of disks.

diskpart
list disk
select disk #
clean
create partition primary
select partition 1
active
format quick fs=fat32
assign
exit

You can also use a rewritable DVD for this, for example my rusty Macbook and my wife's Macbook Pro refuses to boot from this flash drive (possibly a UEFI boot issue, DVD works), but it's bootable on everything else. At this point you can simply copy the contents of the Media folder to the drive, or use one of these commands:

rem Format the flash drive H: and copy the Media directory on it
MakeWinPEMedia /ufd C:\WinPE H:
 
rem Create a bootable ISO that you can burn onto a CD or DVD
MakeWinPEMedia /iso C:\WinPE C:\WinPE\WinPE.iso

Once your flash drive is ready and it works, you can simply replace the Sources\boot.wim file on it after you applied some changes, no need to format the drive again. If you don't want to deal with localization at all, you can remove the da-DK kind of directories in the Media directory and its sub-directories to clean it up, but you should keep en-US everywhere.

Disk partition backup and restore

Now that your Windows PE Rescue Disk is ready, you can do your periodical hard disk partition backups, and restore from them when it's necessary. For an always working copy of your system disk partitions, copy them with Partition Wizard to a secondary disk where you left out enough partitioned or unallocated space for them. You can use the rest for additional data storage, like I do on my workstation. If you want, you can create the partition during coping onto an unallocated space and can set a different size to expand or reduce it. Make sure you choose the same partition type (Primary for me) and set the copy of the system partition Active.

Backing up partitions with MiniTool Partition Wizard
Backing up partitions with MiniTool Partition Wizard

You can also use ImageX that you added to your Windows PE system, like this:

rem Backup partition C: into a single WIM file
imagex /capture C: D:\backup.wim "Backup"
 
rem Restore partition C: from a single WIM file
imagex /apply D:\backup.wim 1 C:

When you copied or restored the system partition, you have to make it bootable with the commands below, set up for Windows Vista or later versions. I used drive C: in this example but it works for any drive letter you want to handle, for example a bootable backup partition on another drive might be on E: after you assigned a drive letter to it.

bootsect /nt60 C: /mbr
 
bcdedit /set {bootmgr} device partition=C:
bcdedit /set {default} device partition=C:
bcdedit /set {default} osdevice partition=C:

That's it! According to my Plan B, if my SSD dies, I just make my HDD the primary disk and boot from it, restore some recent file backups and wait until I can get a new SSD because I'm way too addicted to its amazing speed by now. :-)


Going Clean And Static

One of my handful of New Year's resolutions is maintaining my website more actively. I wanted to make some structural and design changes as well, so a couple of weeks ago I changed the Url scheme to this more common date-based one, then I started working on a refreshed look and a new blog engine. The articles are still being edited with a tiny custom CMS, but now the website itself is made of all static Html files, as opposed to being dynamically rendered on each page view. How long does it take to regenerate all the existing articles and the supporting pages? About one second. :-) With this step not only I gain more performance and significantly decreased RAM usage, but the site can be safely hosted on practically any webserver, including that dinky little one I wrote back in 2000 in C for my colleagues' biggest amusement. Heck, I could host it from a router with a pendrive.

I liked the simple and clean look of the old site, so I didn't change much in that department, just made it even cleaner in order to achieve my major goal here: now it's Responsive. Yeah, the biggest designer buzzword of 2012. If you change the browser size, you will see how it scales down to the commonly used mobile resolutions: 320, 480 and 768. It may not support every display size but the usual ones I care about are covered, it works nicely on iPhone, Windows Phone and iPad. Not only that, but if you view it with a High DPI device (retina display), the design elements are in high resolution, along with most of the illustrations in the articles. For this I edited most of the old entries to display high resolution images too beside the normal, recreated ones and they get nicely replaced via JavaScript on each page load. The CMS helps in it a lot, as the articles are in a custom format similar to Markdown and the Html transformer can check and insert image properties into the final result. The illustrations are not displayed in high resolution on small phone screens in order to save on data, there the normal images often need to be scaled down anyway. The design itself is high resolution on iPhone 4 or newer, even on Windows Phone 7 and 8 which was a bit harder to figure out as it doesn't support the usual media query property for checking the device pixel ratio. Probably I'll write about the solution in a later article. Anyway, it all looks gorgeous on the mobile devices found in my household, especially on my 3rd generation iPad.

Among other changes and additions the site got a wider content area with up to 700 pixels wide images. On a desktop browser if you see the pointer changing to a resize icon over an image, you can view the high resolution version in a lightbox. The typography is beautified by the Segoe UI font, even on clients that don't have this font installed. The internal and external links are handled in a nice and consistent way and there is a source code formatter for snippets (see this example). I added a search feature to the right hand corner, powered by the only dynamic page on the site. I might tweak it in the future but it gives nice and relevant results already. Needless to say, the first use of it was by a Japanese guy who tried to do some SQL injection... SQL Parameters, dude.

Finally here is a visual comparation with screenshots, it will come handy in the future too when nobody remembers what the site looked like several generations ago. I hope you will be as pleased with the new site as I am.

Old look vs New look
Old look vs New look

Windows 8 Customized

Even though I was truly satisfied with Windows 7, I decided to jump on the Windows 8 bandwagon right after it was released. Upgrading for $40 is a really nice offer and as a developer, I will be pressured to switch anyway. For example the Windows Phone 8 SDK requires Windows 8 Pro, mainly because the emulator uses Hyper-V. Like many others, I miss some features that I've been using for many years. I'm the guy who keeps his Start Menu programs tidy, structuring the applications nicely, deleting useless entries, pinning some programs to the top of the menu, using the program history. I pin only those programs to the taskbar that I run at least once a day. I love to have some useful gadgets on the desktop to monitor system activity, see the clock, calendar and the weather. Without the start menu and gadgets I would feel bad, this is the way I like my system, don't mess with it.

Fortunately there is a way to put the missing features back (well, sort of). For a Start Menu replacement I use Start8 from Stardock, it's really good, customizable and it's totally worth $5. To put the Gadgets back, I use 8GadgetPack which is a free Vista Sidebar installer and it comes with plenty of gadgets by default. It needs a little tweaking, I set Aero Glass disabled, top buttons hidden and I copied my previously backed up gadgets to C:\Users\Username\AppData\Local\ Microsoft\Windows Sidebar\Gadgets to install them, now that Microsoft killed the Gadgets Gallery... The end result is pretty neat and I'm really satisfied with it.

Windows 8 desktop after some tweaking.
Windows 8 desktop after some tweaking.

Coincidentally I start this new era of computing with a new workstation, an Ivy Bridge i5-3570K with 4 CPU cores (3.4 / 3.8 GHz), H77 chipset and 32GB of DDR3 1600MHz RAM. The system uses a 256GB SSD and the whole thing is in an industrial design Silverstone MicroATX case. Silent but deadly. I doubt I would need to touch it in the next 5 years, I like to at least double my previous workstation's single thread performance on each upgrade to get the biggest bang for my buck.


Visual Studio 2012 Theme

When I checked out Visual Studio 2012, the first thing I noticed was how badly it looks and feels. You can choose from two color themes: Light for depressed developers (gray over gray) or Dark for the uber h4xx0r stranded in mom's basement. The Light theme doesn't look that bad on the screenshot below, but it would really suck the life out of me after a while and the new black icons in the Solution Explorer just make things worse. I'm not a big fan of this new design direction of Microsoft, but that's a subject for another article.

Meanwhile the extension Visual Studio 2012 Color Theme Editor has been released by Matthew Johnson, he created the amazing theme editor for VS2010 too, which helped me to create my similar theme a couple of years ago. The new editor comes with some themes to choose from, including Blue which is similar to the standard VS2010 theme if you loved that one.

It took me quite some time, but I managed to recreate my Classic Silver-Blue theme starting out from Light. The overall picture is very positive, everything is themed nicely, including the Start Page, output windows and dropdown lists; I already feel much better working with it. Take a look and compare the themes! If you prefer the standard Light one, that's okay; I can imagine it growing on me after a while, but at least we have a choice.

My Classic Silver-Blue themeMy Classic Silver-Blue theme
Standard Light themeStandard Light theme

Unfortunately the editor doesn't have an easy import/export function yet, but I put notes into the theme package about the installation procedure. It's not hard at all, but involves some file copying and adding settings to the registry. Beside the editable version, you can install the theme in static mode without installing the theme editor, too. Bonus patch to change the uppercase menus is included separately. Also, if you can't stand them, there is a way to patch the icons with the ones from VS2010, but I don't want to go that far. Probably it's better to get used to the new ones to avoid future disappointment and frustration.

Classic Silver-Blue Theme for Visual Studio 2012Static and editable color themes for Visual Studio 2012

WebDeploy Tool

Recently – like many others – I checked out Visual Studio 2012 to see what kind of problems a version jump would cause in my most important projects. I was too skeptical, all of my projects loaded and worked in the new version, even with building for .Net Framework 4.5. So far so good, but then I had to realize that the Web Deployment Projects plug-in won't be available from now on. VS2012 comes with a very cool publishing wizard, as long as your project is a Web Application. If you won't or can't upgrade from a Website Project then your only choice is the rather dumb Publish function which doesn't generate the best result and it can't merge assemblies created for the website project. Easy publishing to a specified folder and merging the randomly named App_whatever assemblies into a single assembly was the sole reason I used WDP. Unfortunately I can't really transform my projects into Web Application project types, it would cause too much work for too little gain, so I rolled out my own command line tool WebDeploy to solve this problem. :)

Key functionality is provided by MSBuild to build the Solution and ILMerge (latest version) to merge the project assemblies into a single assembly. WebDeploy configures and runs these, updates assembly references in your relevant project files and gives a helping hand in cleaning up and running additional tasks, doing it all by using the Settings XML file that you personalized for your project. To prove that I take dogfooding seriously, this website has been compiled and published by using WebDeploy.

Just to avoid a possible misunderstanding, I better clarify that you don't need to run Publish or anything in Visual Studio before running WebDeploy. Once your project is ready to upload (works, rebuilds without errors), just run WebDeploy.exe MySettings.xml (obviously with full paths if needed) and it will rebuild and fix up your website project using the provided Solution file and other settings. Aunt Edna mode off. :)

You may check out where the default Publish function is building your website, for me it always happens to be (Project folder)\PrecompiledWeb\myproject.local (the website's local URL for IIS in my system). Weirdly enough, if I change the Output Folder using Property Pages -> MSBuild Options, it doesn't actually change the AspNetCompiler.TargetPath values in the Solution (.sln) file, so if you're not satisfied with the default Output Folder, you may have to edit the solution file manually. It has to be done only once. WebDeploy can handle all variations of Updateable website and Use fixed names settings, in my setup these options are Updateable=true and FixedNames=false.

After building the project, your selected assemblies will be merged. In my experience all these assemblies are named in the pattern App_*.dll so the default entry in the Sample.xml file will be fine for most (if not all) cases. Choose a simple and unique assembly name for merging target and the references in project files (aspx, ascx, master – the list is editable in the app's .config file) and .compiled files will be updated to use the single assembly's name. Mind you, my Solutions contain 1 website project and multiple library projects, so you may have extra configuration needs if yours is more complicated, like it has multiple websites. You can set up plenty of things in the Settings.xml file, see the provided Sample.xml values and the MSBuild manual, if needed. No worries, chances are you won't need to do anything special above putting sensible values into the provided XML nodes.

You can set up a list of files that should be deleted after building and merging, and you can also set up a list of shell commands to execute before and after building. With this you can easily script a clean up so you won't upload not needed (or server dependent) files and compress, maybe even upload the prepared website.

Just make a copy of the Sample.xml file and change it around for your own projects, I'm pretty sure you'll be satisfied with the result. As it turned out, it's significantly faster than Web Deployment Projects on the same hardware, over twice the speed for me. ILMerge and the full source code is provided with the tool.

WebDeploy ToolWeb Deployment Projects replacement for Visual Studio. Requires .Net Framework 4.0

Wikipedia Fail

Even though Wikipedia is a great thing, the concept of letting anybody edit the pages surely has its drawbacks. Of course Kim Ung-Yong is a former child prodigy and the entry has been fixed by now; only Google needs to re-index it, rather sooner than later...

Google search for Kim Ung-Yong, first match...Google search for Kim Ung-Yong, first match...