Thursday, January 22, 2009

Some VM Tools

To create Virtual Machines for use with VMWare a VMX Builder is available here.
Instructions on how to convert from scsi to ide disk are posted here.

I'm trying to collect all the free tools and scripts out there to allow manipulation of virtual machines and virtual disks.
Still no idea on what to use as a standard. I think it will be .vmdk for now. For virtual machines it will be VirtualBox. And I'll still have to use VMWare Player and VirtualPC for machines created with these tools. Some operating systems won't run after disk conversion or if run under VirtualBox, although it supports all types of virtual disks above.

Deploying a WCF Service with IIS 7

I did expect it to be this simple but I could not believe it would really be that way. All it takes for a WCF service to be deployed to IIS box is the following:
  1. Copy .svc file into a web site folder on the server,
  2. Copy .dll file into a \bin subfolder in the web site,
  3. Copy web.config or create a new one. It has to have the endpoint configuration. The one created by default by Visual Studio 2008 simply references "localhost", which seem to be fine.
  4. "%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -r -y
Assuming the service has been tested through Visual Studio 2008 on the development box, this is it!
Navigate the browser to that http://<server>/<service>.svc and you will see the service front page. The step #4 is required for WCF to work IIS OOTB.

This works for the default option of BasicHTTPBinding and no specific endpoint or binding configuration. The point was to get it working. All the nitty-gritty stuff comes later.

Wednesday, January 21, 2009

Automatic Logon in Windows Server 2003

How to turn on automatic logon in Windows

To avoid having to log on to Windows 2003 follow the steps below. Some might wonder why would anyone do such a thing as remove authentication from a server operating system. I think they are suffering from lack of imagination. :)
Running a Windows Server in a virtual machine environment is a perfect example where I don't want to type a password for all the virtual machines around.

To use Registry Editor (Regedt32.exe) to turn on
automatic logon, follow these steps:
  1. Click Start, and then click Run.
  2. In the Open box, type Regedt32.exe, and then press ENTER.
  3. Locate the following subkey in the registry:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
  4. Double-click the DefaultUserName entry, type your user name, and then click OK.
  5. Double-click the DefaultPassword entry, type your password, and then click OK.NOTE: If the DefaultPassword value does not exist, it must be added. To add the value, follow
    these steps:

    1. On the Edit menu, click New, and then point to String Value.
    2. Type DefaultPassword, and then
      press ENTER.
    3. Double-click DefaultPassword.
    4. In the Edit String dialog, type your password and then click OK.
    NOTE: If no DefaultPassword string is specified, Windows automatically
    changes the value of the AutoAdminLogon key from 1 (true) to 0 (false), disabling the AutoAdminLogon

  6. On the Edit menu, click New, and then point to String Value.
  7. Type AutoAdminLogon, and then press
  8. Double-click
  9. In the Edit String dialog box, type 1 and then click OK.
  10. Quit Registry Editor.
  11. Click Start, click Shutdown, and then type a reason in the Comment text box.
  12. Click OK to turn off your computer.
  13. Restart your computer. You can now log on

Software as a Service - Online Database

Dabble DB - Create an Online Database - Collect, report, and share your data

One more Web 2 (or 3) application that continues the trend of "software as a service". Here I count only the applications that are actually useful and can replace something that already exists while also adding some new value (features, options, etc.).
Dabble DB is one of them. It offers a free version of the service which allows up to 100,000 records in a database and 15 users sharing the data. Perfect for small-scale projects. Available everywhere around the world where internet access exists.
Dabble allows creation of input forms, reports, charts - seems everything one needs for a simple database project is there.

Create .vmdk with QEmu

QEmu-Img, a tool that comes with QEmu package, can create new .vmdk virtual drive images. This should be enough to satisfy most of the functionality needed to work with virtual machines yet to keep all the software free (Open Source).
Together with VirtualBox, this makes a strong VM combination. VirtualBox supports all its functionality while using .vmdk drive images.

The command parameteres are listed below:
qemu-img version 0.9.1, Copyright (c) 2004-2008 Fabrice Bellard
usage: qemu-img command [command options]
QEMU disk image utility

Command syntax:
  create [-e] [-6] [-b base_image] [-f fmt] filename [size]
  commit [-f fmt] filename
  convert [-c] [-e] [-6] [-f fmt] [-O output_fmt] filename [filename2 [...]] out
  info [-f fmt] filename

Command parameters:
  'filename' is a disk image filename
  'base_image' is the read-only disk image which is used as base for a copy on
    write image; the copy on write image only stores the modified data
  'fmt' is the disk image format. It is guessed automatically in most cases
  'size' is the disk image size in kilobytes. Optional suffixes 'M' (megabyte)
    and 'G' (gigabyte) are supported
  'output_filename' is the destination disk image filename
  'output_fmt' is the destination format
  '-c' indicates that target image must be compressed (qcow format only)
  '-e' indicates that the target image must be encrypted (qcow format only)
  '-6' indicates that the target image must use compatibility level 6 (vmdk form
at only)

Supported format: parallels qcow2 vvfat vpc bochs dmg cloop vmdk qcow host_devic
e raw

Tuesday, January 20, 2009

Windows Server 2008 and File Extensions - Bug?

I had a few file extensions set to open with programs located on my mounted I: drive. Then I moved the files to C: and removed the mounted drive.
Windows Server 2008 went crazy with file extensions that were linked to programs on (now) non-existent drive. It was impossible to select another program as the default. I had to manually open the registry and search for previous location and change it to the new drive. After that everything worked as usual.

Monday, January 19, 2009

Creating a virtual machine from a real one - Virtual disk resources

Here are some tools that might help in creating a virtual machine from a real one. Some of them create only a virtual hard disk drive image, which can be enough since creating a new virtual machine is rather simple with VirtualBox or other virtualization programs.

QEmu package can be used to create new .vmdk virtual drive images and then the following programs can be used to copy files from an existing system, or mount an existing virtual drive and copy, or any other combination possible.

Free software:

Additional free software listed here.

Free alternatives (trial, home, shareware, etc.):
Commercial software:
  • VMWare, both Workstation and Server, offers the feature of creating a VM from a physical one but I had no luck using this feature;
  • Acronis True Image
  • AyRecovery (home), previously EAZClone
  • DriveBackup, from Paragon
  • Norton Ghost
  • Image for Windows from Terabyte. There is also BING (BootIt Next Generation)
  • ShadowProtect If you run across some other packages, let me know.

Sunday, January 18, 2009

VirtualBox - No Network Adapter on Windows XP

I had an issue with a guest Windows XP in a virtual machine. It could not recognize neither of the network cards (NICs) offered by VirtualBox.
Here are the links for Intel, and AMD network card drivers. I used the driver (available here) and everything was alright after the driver installation.
Funny the driver was not available on the manufacturer's site for Windows 2008 Server.

Source for the links - here.


JkDefrag is a great free defragmentation tool for Windows. I'm using it more and more instead of all the other defragmenters out there. It is fast and does a decent job defragmenting.
To complement the functionality of JkDefrag, it is recommended to use

  • Page Defrag (link), for page file defragmentation,
  • NTRegoPT (link), for registry defragmentation

JkDefrag GUI is a nice addition to JkDefrag that makes all the functionality of the underlying program through a graphical user interface. You can schedule defragmentation runs, select options, install screen saver defragmenter, etc.

I'm having issues running the above listed programs on Vista and Windows Server 2008. Not sure if they work correctly or at all.

VMWare Disks

To merge pieces of a virtual disk image that is split into multiple 2GB files back into one file, use


There are some GUI tools that server as wrappers around it, should you need them. Some of these GUI tools are the following:

Disk Manager is also used to increase the size of a virtual hard drive image or perform other maintenance operations.


VMware Virtual Disk Manager - build 126130.
Usage: vmware-vdiskmanager.exe OPTIONS <disk-name> | <mount-point>
Offline disk manipulation utility
  Operations, only one may be specified at a time:
     -c                   : create disk.  Additional creation options must be specified.  Only local virtual disks can be created.
     -d                   : defragment the specified virtual disk. Only local virtual disks may be defragmented.
     -k                   : shrink the specified virtual disk. Only local virtual disks may be shrunk.
     -n <source-disk>     : rename the specified virtual disk; need to specify destination disk-name. Only local virtual disks may be renamed.
     -p                   : prepare the mounted virtual disk specified by the drive-letter for shrinking.
     -r <source-disk>     : convert the specified disk; need to specify destination disk-type.  For local destination disks the disk type must be specified.
     -x <new-capacity>    : expand the disk to the specified capacity. Only local virtual disks may be expanded.
     -R                   : check a sparse virtual disk for consistency and attempt to repair any errors.

  Other Options:
     -q                   : do not log messages

  Additional options for create and convert:
     -a <adapter>         : (for use with -c only) adapter type (ide, buslogic or lsilogic)
     -s <size>            : capacity of the virtual disk
     -t <disk-type>       : disk type id

  Options for remote disks:
     -h <hostname>        : hostname of remote server
     -u <username>        : username for remote server
     -f <filename>        : file containing password
     -P <port>            : optional TCP port number (default: 902)
     -S                   : specifies that the source disk is remote, by default  the remote options are assumed to refer to the destination.
  Disk types:
      0                   : single growable virtual disk
      1                   : growable virtual disk split in 2GB files
      2                   : preallocated virtual disk
      3                   : preallocated virtual disk split in 2GB files
      4                   : preallocated ESX-type virtual disk
      5                   : compressed disk optimized for streaming

     The capacity can be specified in sectors, KB, MB or GB.
     The acceptable ranges:
                           ide adapter : [1MB, 950.0GB]
                           scsi adapter: [1MB, 950.0GB]
        ex 1: vmware-vdiskmanager.exe -c -s 850MB -a ide -t 0 myIdeDisk.vmdk
        ex 2: vmware-vdiskmanager.exe -d myDisk.vmdk
        ex 3: vmware-vdiskmanager.exe -r sourceDisk.vmdk -t 0 destinationDisk.vmdk
        ex 4: vmware-vdiskmanager.exe -x 36GB myDisk.vmdk
        ex 5: vmware-vdiskmanager.exe -n sourceName.vmdk destinationName.vmdk
        ex 6: vmware-vdiskmanager.exe -r sourceDisk.vmdk -t 4 -h esx-name.mycomp \
              -u username -f passwordfile "[storage1]/path/to/targetDisk.vmdk"
        ex 7: vmware-vdiskmanager.exe -k myDisk.vmdk
        ex 8: vmware-vdiskmanager.exe -p <mount-point>
              (A virtual disk first needs to be mounted at <mount-point>)


From what I read it appears that VirtualBox is a viable alternative to VMWare, not to mention VirtualPC. The installation size is about 30MB, the performance is better to VMWare, the interface is less annoying than VMWare Server, and it supports both .vhd and .vmdk virtual disks! This means you can use both your VirtualPC and VMWare disk images.
The link above contains instructions on how to migrate an existing Windows machine or a virtual machine to a new VirtualBox virtual machine.
From my experience, the performance is very good. Software feels very lightweight and is easy to use and configure on the fly.

Hard disks

VirtualBox has a concept of storing all the hard drives together. The simple reason for this approach, instead of storing a hard drive together with a virtual machine, is that is supports differencing hard drive images. Some complex setups are available as a result of this.
I hope to test a setup where there is one installation of an operating system (for example, XP) and then there are differencing hard disk images that branch into a development disk and a personal disk.
As I read beforehand, it does read both .vhd and .vmdk drive images. I successfully ran a new virtual machine from both .vhd and .vmdk existing virtual drives.
Immutable images is a feature where a VM starts off an existing hard drive image but all the changes are stored in a separate file - a differencing disk.
It also supports snapshots. While I have had some issues creating snapshots with .vmdk files, the help file states:
"Initial support for VMDK was added with VirtualBox 1.4; since version 2.1, VirtualBox supports VMDK fully, meaning that you can create snapshots and use all the other advanced features described above for VDI images with VMDK also."
To convert between different virtual disk image types, use Qemu's img tool. Qemu for Windows available here.
VBoxManage is the command-line tool that is a part of VirtualBox installation and is used for various actions. One of them is conversion of virtual hard drive images.

Seamless Windows

VirtualBox supports Seamless Windows (source). This is a neat feature and means that you can have application windows from the virtual machine being displayed on your real machine!

Shared Folders

Shared folders are supported between the host and the virtual machine.
Many advanced tools are available through command line. While that might be a hassle, at least the functionality is there - compact virtual disks, create an immutable disk, etc.
To migrate an existing Windows installation or a virtual machine, follow the instructions posted here.

Thursday, January 15, 2009

Optimizing Linq to SQL

Lazy Loading in LINQ: LoadWith And AssociateWith DataLoadOptions - Part 1 - LoadWith - Hilton Giesenow's Jumbled Mind

Above is the link to one of the articles I would recommend if you are using Linq to SQL and are now in a situation to tailor solutions to specific problems and/or optimize the performance of your code that is using Linq to SQL for data manipulation purposes.

One thing that we are going to use in the next project, that is different to default Linq setting, is usage of Stored Procedures with Linq entities.
We are creating partial classes for Linq entities and put the static functions in there that call the stored procedures to return sets of those entities. So, we are mapping result sets from stored procedures to entities. I want to try to get a single result from a call to an SP and map it to multiple entities and see how it works.
Next thing is that we are inheriting the original data context and add the function calls there to provide access to the SPs and return the desired data type instead of automatically generated one.

In the article above there are a few tips to have in mind when playing with Linq. DeferredLoadingEnabled and DataLoadOptions, that provides LoadWith and AssociateWith, are a few interesting points. In the given example, Linq is using a JOIN in SQL statement to fetch the resultset containing multiple entities. Sweet.

Tuesday, January 13, 2009

Mocking Around

While I have been playing with NMock library I found out that NUnit includes mock library as well. Never came across that before. I am ashamed, I admit.
Nonetheless, NMock has better syntax and seems more intuitive to use. The advantage of NUnit mock library is that it is a part of NUnit package. That advantage goes away, though, when unit testing libraries from .Net Framework are used for unit testing.

NUnit's mock library has a weird case when properties are accessed as the syntax for accessing a property has to include "get_" or "set_" before the property name. Also, the accessing of the property itself is a bit counterintuitive. NMock, on the contrary, offers ease of use as the mock object implements the interface and can be used in tests in a very simple and straightforward manner. It is a matter of preference. I prefer it simple.

Another thing I found out about mock objects is that they have to mock Interfaces, not Classes. While this may be obvious to some, I did not realize before what is the issue with creating all the interfaces. Now I have to look at that aspect of TDD. Some redefinition will occour on the way I develop software and hopefully the results will be even easier maintenance of the code I write as well as reusability.
One issue I ran into is that interfaces have to be public. While this may be obvious to some, it is new to me. And it is an issue to have in mind.

Now, having a mock framework in place, the stage is set for some real unit testing. The tests I did before were not pure unit tests because all the units (classes) had their dependencies on other units, or data, or some other external unit. Off to do some real TDD... :)


Here is a sample unit test:

public void test_nmock()
Mockery mock = new Mockery();
ISetting s = null;

s = mock.NewMock();
catch (Exception ex)


Assert.AreEqual("35", s.SettingValue);

Enable Windows Search on Windows Server 2008

Bilal Haidar [MVP, MCT] : Install Windows Search Service on Windows Server 2008

I need a desktop search program that will help me find the different texts I have all around my workstation. Windows Search is not automatically enabled on Windows Server 2008 and it is a bit different to enable it than on Vista.
As listed in the post linked at the top of this article, the steps to have the Search service up and running are the following:

  1. Go to the Server Manager
  2. Click on Add Roles
  3. Select File Services
  4. Select Window Search Service
  5. Select the drives you want WSS to have control on
The Search service can be fine-tuned after installation through a plug-in in Control Panel.


NMock: A Dynamic Mock Object Library for .NET

NMock is a framework for .Net that allows creation of mock and stub objects in Test Driven Development using Microsoft .Net Framework.
The documentation is enhanced and there is a tutorial explaining the concepts. This framework is a necessary addition to Unit Testing framework as it allows to isolate the unit being tested. The external dependencies are replaced with mock/stub objects and provide the expected output. That way, if your class retrieves data from a database and the test depends on it, stub object can be created that fits the expectations. The class will receive what it expects and it will get tested properly. The test will not fail for reasons outside the tested unit, for example - not running database server, or wrong data in the database, etc. This is, of course, unless you are doing some database tests. :)

Quickstart and Tutorial available on the site.

Monday, January 12, 2009

My.Resources in C# and Icons

To embed icons in a windows application, it is very easy to store them in the Resources. A new file can be added or a default one used. It can store strings, images, icons, etc. Once the icons are stored in the Resources.resx they can be accessed through


which is the equivalent of My.Resources from Visual The easiest way to use icons is to create and fill an ImageList, which is then utilized by TreeView or ListView.

            tvw.ImageList = new ImageList();
            tvw.ImageList.Images.Add("FolderIcon", Properties.Resources.FolderIcon);
            tvw.ImageList.Images.Add("ItemIcon", Properties.Resources.ItemIcon);

Sunday, January 11, 2009

Unit Test Patterns for .Net

Unit Test Patterns for .NET development - Part I

Here is a series of excellent articles on Unit Testing patterns.

Disk Cleanup: WER Files

While running JkDefrag I noticed that there are many WER report files. Windows Error Reporting files are located in your profile folder (C:\Users\<user>\AppData\Local\Microsoft\Windows\WER). There are Gigabytes of these files that noone really needs. To remove them, use DiskCleanup utility in Windows so that they are deleted properly.

The same utility can be used to delete older restore points and free some additional space provided you need the later and not the former.

Forced dismount of an USB drive

The operating systems I use seem to like my USB external drive so much that they hardly want to let go of it once it is attached. Hence, I'm looking for a nice way to force them to release the handles on the drive and allow proper disconnect.

The only way I found so far is to use chkdsk /f on the drive, which seems to call some API that does what is required.

Error installing Expression Web 2

"Installation of the "Microsoft Expression Web 2" product has reported the following error: -2147024873."

I can not install Expression Web 2. Some people in the forums mention different causes and solutions.
My first try is to remove Office 2007 Enterprise and try installing Expression Web 2 again. That did not change anything. After this, I went into "installer" folder under Windows and manually removed all the remains from Office 2007. Still no progress. Expression Web 2 installation fails.
Then I installed Office 2007 Ultimate and, after that, Expression Web 2 installed successfully. Weird.

Saturday, January 10, 2009

PerfectDisk 2008 Boot-Time Defragmentation Not Working

When attempting to perform a boot time or offline

I tried to perform a boot-time defragmentation of the system drive with PerfectDisk 2008 but it failed complaining about non-compatible driver and being unable to lock the system drive.
Fortunately, software has an option of scanning the system to find known incompatible issues and help in fixing them. In my case it reported sptd.sys. Using that as a keyword I was able to find the above page in the Support section. Reading through that, I realized I had more than one issue...
  1. SPTD is a driver used by Daemon Tools. Updated driver, that does not lock the system drive during boot-time, can be downloaded from here.
  2. Comodo Firewall. Registry entry "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\inspect.sys\Start", contrary to the support article, contained 3. This one is changed manually using RegEdit.
Unfortunately, handling both of these issues did not help at all. Still can't do boot-time defragmentation.

I finally found some time to fix this issue. The resolution is listed in a new post - here.

Thursday, January 08, 2009

Live Mesh Community

In order to fix things with Live Mesh, as it is still in beta stage, it is necessary to be a part of community. So, hereby are the links to important places related to Mesh...

  • Connect site, used to submit bugs and report issues directly to development team.
  • Forum, used for discussion about Live Mesh. Some help can be received here, too.
  • Blog, used to announce developments and issues by the development team.
There are other sites and blogs related to Mesh, usually maintained by development team members. When I run into one of those again I will post the links here.

Wednesday, January 07, 2009

Mesh Conflict Resolution - A Tip

Here's a golden tip if you have many conflicts in Live Mesh: Go offline! Simply set Mesh client to work in offline mode and save yourself a ton of time. Mesh client tends to send changes you make in conflict resolution back to the server. But, right after that it retrieves the feed with changes back and does something to it. Whatever it is, it is taking a lot of processor power and is slowing the whole process significantly.
Many hours have been wasted before this realization. Use it. :)

Mesh Synchronization Issues - Won't Download

Update 2009-01-20:

A tip from Microsoft states that attached drives (USB, network, etc.) are treated differently than the physical ones. As I was using a TrueCrypt virtual drive this was causing the problem. Files and folders synchronize if attached to a physical drive!

Original post:

I'm having strange issues with Live Mesh today. There are a couple of folders where I noticed different problems.

- One folder, containing keepass database does not synchronize at all. No matter what I do (stop synchronizing and start again, uninstall Mesh and install again) it does not download files from the Live Desktop onto the computer I'm currently using. The synchronization used to work but is now acting strange.
The only thing I notice is that the folder is marked with attribute R, for Read-Only. That is funny because this is how the folder is marked when Live Mesh creates it. Even if I stop synchronizing and delete this folder, then create it automatically by subscribing to that folder through Mesh, it still gets the R attribute. Manually removing the R attribute does not change a thing and files are still not synchronized.
I have to say that Mesh DOES download the files but it does not create them in the folder. I checked the permissions and could not find anything wrong. The Moe runs under my account credentials and it is a member of administrators.

I also uploaded file through browser directly to Live Desktop. The file gets downloaded, technically, which can be seen as the progress bar for download activates after a few seconds. But, the file is not created in the local folder.

Must be something with permissions or UAC, unless it is a service and client change at Microsoft again.

Checked through the log. The error reported is the following:

ErrorDescription=System.IO.IOException: Failed to move the file with TxF C:\Users\siljaka\AppData\Local\Microsoft\Live Mesh\GacBase\Assembler\97bc5936-399e-4998-92fc-3c233039a2ac-d1f9284d-be0d-4da8-999b-ddca4e02bae2.fnl to I:\Alen\devel\Windows Sidebar Gadgets\blah.txt! Error = 6801
at Microsoft.Live.Moe.Synchronization.Platform.FileSystemRealizer.TxFFileSystemRealizer.CreateFile(String path, String downloadedPath)

Tuesday, January 06, 2009

WCF and Linq to SQL

Since Linq to SQL creates a nice data model, there is no point in re-creating the entities again as DataContract objects that can be serialized and sent to clients. Linq entities can be used directly, saving you some time. But, this is not the default behavior.
To enable this behavior open the data model (dbml) in designer and then go to Properties. Adjust Serialization Mode to Unidirectional as in the image below

That is all. The entity objects are now serialized and can be returned directly from a web service call. They can be sent either individually or as a part of a collection/list. Wonderful.

Linq Deferred Execution

Linq defers the execution of a query until either of the following is encountered:
  • .ToList()
  • foreach
This means that the query is sent to the data source (i.e. SQL Server) only once the code reaches one of the above statements - when the query results are actually needed to be used.

Friday, January 02, 2009

memcached: distributed memory caching system

memcached: a distributed memory object caching system

This solution has been recommended somewhere as the solution to reduce the load on database. It is another distributed memory caching system, similar to NetScaler or Velocity.
It's focus in on alleviating database load in web server applications environment. The magic it does comes from its scalability. It utilizes multiple servers and distributes load to their memory and CPU power.
There is a story of caching that, in an interesting way, explains how memcached works.