October 3, 2023

Y M L P -229

How Communication Happens

Distinctive Hardware ID in C#

Any laptop or computer has components that carry a certain serial variety. Some figures are assigned when the operating system is installed, but some are actually embedded in the hardware. Using C#, numerous embedded serials can be combined to develop a one of a kind computer ID.

Why a one of a kind serial? A easy reason is for branding software program to a certain computer. A most likely inflexible licensing process, it can be fairly successful relying on how it is used.

For this short article we will use two serials, the challenging travel and the CPU. Equally will be obtained with the created-in C# course System.Management.

If you develop a New Task in Visual Studio 2005 (any of the editions), you will see the line “utilizing Process.Administration” does not work. You have to increase it manually:

  • Go to the Resolution Explorer
  • Suitable-click on References and click on “Insert Reference…”
  • Come across System.Administration from the .Net tab.

When set up it is uncomplicated to get the components ID’s.

The tough generate ID’s depends of course on the harddrive. Below is the pseudocode:

  • Create a ManagementObject with the string “earn32_logicaldisk.deviceid=[drive letter here]:”
  • Accessibility the serial with the index “VolumeSerialNumber”, for case in point disk[“VolumeSerialNumber”] where disk is the ManagementObject

The CPU ID is basically alternatively flexible also. Numerous computer systems today have far more than just one CPU. You use the to start with one as in my case in point, or a number of kinds:

  • Build a ManagementObject with the string “gain32_processor”
  • Go as a result of the out there processors
  • Access the house like so: managObject.Properties[“processorID”]

Combining them can be basic or advanced. Just adding them collectively in a row operates just fantastic. For my example some redundant 0’s are eliminated prior to coming the ID’s of the to start with offered drive and the very first CPU.

Check out it out to see how the quantities appear.