Software full of Performance

Any computer has components that carry a specific serial number. Some numbers are assigned when the operating system is installed, but some are built into the hardware. With C#, multiple embedded serials can be combined to create a unique computer ID.

Why a single series? One simple reason is branded software for a specific computer. A perhaps inflexible licensing system can be quite effective depending on how it is used.

For this article we will use two serials, the hard drive and the CPU. Both will be obtained with the built-in C# System.Management class.

If you create a new project in Visual Studio 2005 (any edition), you’ll notice that the “using System.Management” line doesn’t work. You have to add it manually:

  • Go to Solution Explorer
  • Right click on References and click “Add Reference…”
  • Look for System.Management in the .Net tab.

Once configured, it’s easy to get the hardware ID.

The hard drive ID obviously depends on the hard drive. Here is the pseudocode:

  • Create a ManagementObject with the string “win32_logicaldisk.deviceid=[drive letter here]:”
  • Access serial with index “VolumeSerialNumber”, for example disk[“VolumeSerialNumber”] where disk is the ManagementObject

CPU identification is also quite flexible. Many computers today have more than one CPU. You use the first one as in my example, or several:

  • Create a ManagementObject with the string “win32_processor”
  • Go through the available processors
  • Access the property like this: managObject.Properties[“processorID”]

Combining them can be simple or complex. Just adding them in a row works fine. For my example, some redundant 0s are removed before the IDs of the first available drive and the first CPU appear.

Give it a try to see what the numbers look like.

Leave a Reply

Your email address will not be published. Required fields are marked *