Installing a virtual network from scratch for developers

I had the opportunity recently at work to install Windows Server 2008 R2 from scratch and setup several virtual machines in a network configuration, and here’s how I did it.

The physical machine has 16 GB memory, and is a dell desktop machine actually! It has 4 cores, but with hyperthreading it shows 8.


Being a software engineer and all, we don’t often get the chance to set up an environment like this from scratch. This was fun, but I’m not a network engineer.


If you only have one network connection on your physical server, make sure you bridge it with the virtual adapter too. Then set the settings on the bridge and not either adapter.


To open ports on “Windows Advanced Firewall”, open a command window as an administrator. Issuing the following command will open port 80 on your firewall for you.

netsh firewall set portopening TCP 80 "Web"

TFS 2010 and SQL Server 2008 R2

Installing both of them on VMs was fairly easy, and fault free, if you follow their install guidelines. Thank goodness too! because TFS 2008 took me 2-3 days… This took less than a half a day.

I have TFS installed and working on two ports, since 8080 is a typical router remote admin port, which is already mapped, and cannot be forwarded outside.

There was a couple gotchas along the way that I needed to refer to blog posts to fix. One is with SharePoint.

You cannot install SharePoint from the Roles. If you do, you still have to download a patch .msi and install that.

Also, to get to create a site in SharePoint (so TFS can use it) you have to run IE as an administrator, and then the “Create a site” link will be visible.

Not to mention the whole “IE Hard Admin” which locks down IE on the server. You have to constantly add the local sites into the trusted sites too.

Exchange 2010

This was a BEAST to install! Really! I ended up installing it twice, both times using only the GUI to install and configure it, with the updates too.

DONT: “Don’t delete your user account from exchange or any other account as it deletes it from the active directory too. I hosed the whole setup that way and had to install all the virtual machines as well as install windows again on the server.

Also, when you install windows, before connecting to a domain, create a user with admin rights, since joining the domain seems to not allow the administrator login to login.”

I installed a SSL certificate for the external access, but internally it still says the cert is invalid, because it’s a local domain, and I now need a ssl cert for the internal one too.

I still haven’t finished the exchange correctly to get it working inside and out. I guess I’ll figure it out later…

EF4 T4 Templates

I just started my first open-source project. EF4 Templates. Yeahhh!

EF4 Templates uses T4toolbox to generate POCO self-tracking entities that can be unit tested, along with validation for WPF, Silverlight RIA services and ASP.NET/ASP.NET MVC. They also generate an ODATA service with authentication for usage with WPF.

Some of the features already implemented:

Self-tracking entities that use IContext and IObjectSet so they can be seperated from EF, and unit tested.

Fake object context for testing purposes.

OData service endpoint for use with WPF or windows forms, including forms authentication.

Validation using sidecar classes like RIA services and DataAnnotiations. A special class is generated for WPF to use DataAnnotations too.

Some of the new features I wish to implement are:

Silverlight domain service with OData endpoint

Right now the templates generate VB.NET code but I soon hope to have more converted to c# too. Wanna help?

Xaml color scheme generator

I’ve made a xaml color scheme generator that works with

It generates a resource dictionary and xaml demo source. In the color scheme generator site, just export to xaml, and save to a file. In the generator, browse for that file, and click convert.

Download it here

Requires .NET 4.0 Client Profile.

Cracking .NETZ executables

.NETZ is a free open source tool that compresses and packs the Microsoft .NET Framework executable (EXE, DLL) files in order to make them smaller. Smaller executables consume less disk space and load faster because of fewer disk accesses.

Today we are going to show you how to extract assemblies from them, so we can crack them!

First, we use reflector to save the resources to a folder. Right-click on the zip.dll and choose Save As… Then do the same for the guid resource.


Then, in reflector, we find the unzip method. It’s in the namespace netz.NetzStarter.Unzip(data() as byte)

So we copy that code to the clipboard, and fire up Visual Studio and make a new console app.

Paste the unzip code to the module, and add namespaces at the top:

Code Snippet
using System.IO;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;

Then we add the following code to the Main() sub.

Code Snippet
public void Main()
    string folder = @"C:\\Cracked\\Files";
    // This is the name of the resource we took from
    // reflector.
    string bFile = System.IO.Path.Combine(folder, "A6C24BF5-3690-4982-887E-11E1B159B249");
    byte[] b = My.Computer.FileSystem.ReadAllBytes(bFile);

    // Attach a .exe to the end of the string
    bFile += ".exe";
    // write the bytes to the file.
    using (MemoryStream ms = UnZip(b))
        byte[] outBytes = ms.GetBuffer;
        My.Computer.FileSystem.WriteAllBytes(bFile, outBytes, false);

And run it. It should make an executable file in the same folder… Happy cracking!

When good code goes bad…

In my post about refactoring code, I wrote on how you can tell how good a programmer is by looking at his code. That got me to thinking: Some stuff that seems simple, is sometimes hard to remember.

For instance, if you want a class to only have shared methods, you should mark it as not inheritable and set the constructor to private.

Public NotInheritable Class SomeClass Private Sub New() End Sub Public Shared Function SomeMethod() as boolean End Function End Class

The code in C# is like so:

public sealed class SomeClass { private SomeClass() { } public static bool SomeMethod() { } }

Sometimes I get lazy and forget to mark it not inheritable, but lately I’ve been using code analysis, and trying to make my code be more like the .net framework libraries and use best practices.

Refactoring someone else’s code

I needed some code to do a function for my work. I found a .NET dll that costs $49 dollars. Well, after looking at it in reflector (which I always do to get a better idea of the architecture), I decided to refactor it.

I could have just used it.

I could have just made it work and had my boss purchase it.

I had already started on something similar when I decided to search the net for code already made, after all, why rewrite the wheel.

Well, the code was OK. You know when you look at someone’s code and you can always tell how much programming a person knows.

This person/people were only beginner/mid level programmers, and they were selling code with no visible programming patterns, had spelling mistakes, many duplications and more. So I used reflector to extract the source code.

Mostly what the code did, was a bunch of classes with properties, and two class that would concatenate the properties to a string, do a http post, and retrieve/parse the xml result to another class named Result.

Fine. So I refactored it, spending 4 hours or so on it. I added a factory pattern to distinguish between the two “gateway” objects that had almost the same code. I added an interface for the gateway. I added a base class for most of the generic properties for the classes, and left only the ones that were different from the base class.

At the end of the day, I got let go from work due to the economy, so did about 1/3 of the company, so I never got to implement this code in a project.

At this point, I would say 70-80% of the code I re-wrote. So the question remains, do I now own the code? or do they still retain rights to it?

At this point, it really only saved me a couple hours of typing in property declarations. What do you think?

Binary hack a .NET executable

I would first like to preface this article in saying: If you’re .net library is being protected by a single boolean function, you deserve to be hacked… 🙂

It’s actually not that hard to binary hack an assembly. I first learned it by reading these blog entries: Part 1 Part 2

When you change an .net executable by re-signing it after hacking, you have a small problem. Any dlls or executables referencing this executable will break because the public key has changed.

You can fix this by round-tripping to IL code and back.

ildasm.exe File.exe /text /

Then edit the public key in the .IL file(s), and run this:

ilasm.exe /exe /output=OutExe /key=PubKey.snk

Voila! All references replaced.


To hack a binary, you need a good hex editor. I use UltraEdit. Here’s the code for a IsLicensed() method.

Code Snippet
  1. public bool IsLicensed()
  2. {
  3.     try
  4.     {
  5.         this.License = LicenseManager.Validate(base.GetType(), this);
  6.         return true;
  7.     }
  8.     catch (Exception)
  9.     {
  10.         return false;
  11.     }
  12. }

All you would have to do is change the Return False to Return True. Not a good way to protect your code. In binary, 16 is false, and 17 is true. so editing one byte changing from 16 to 17 and then re-signing makes a control be fully licensed. The license check will always fail, but by returning true, it’s licensed (as far as it knows). Remember to remove the old one from the GAC, and to update all references.