Any computer contains components that contain a specified serial number. Some numbers are assigned when you install the operating system, but some are actually embedded in the hardware. Using C #, multiple embedded sequences can be combined to create a unique computer ID.
Why is a unique serial? A simple reason for branding software is a particular computer. Probably an inflexible licensing system, depending on how it is used, can be very effective.
We have two sets, hard disk and CPU, for this article. Both are available with built-in C # class System.Management.
When you create a new project in Visual Studio 2005 (any release), you will notice that "System.Management" does not work. You must manually add:
- Go to Solution Explorer
- Right-click References and click "Add Reference …"
- You can find the System.Management command on the .Net tab.
After obtaining the hardware ID, the hardware ID is easy.
Hard drive ID is obviously on the hard drive. Here is the pseudocode:
- Create a management object with the string "win32_logicaldisk.deviceid = [drive letter here]:"
- . Access the sequence for the "VolumeSerialNumber" index, such as [“VolumeSerialNumber”]where the disk is named ManagementObject
The CPU ID is actually quite flexible. Many computers now have more CPUs. You use the first as in my example or several times:
- Create a Management Object with the "win32_processor" string
- Through Available Processors
- Open the property such as: managObject.Properties [“processorID”]
Combining these can be simple or complex. Simply adding in a row works well. In my example, some redundant 0 must be removed before the first available drive and the first processor ID arrive.
Try to see how the numbers look