This is another in a series of articles that will discuss using hardware information for software activation. Previously I discussed using the MAC address, the Video Controller, the CPU, and RAM for this purpose.
The hard drives also provide some useful information that can be used as part of an activation strategy. In .Net we can access information about the hard drives by using theManagementObjectSearcher class in the System.Management namespace (be sure to add a reference to System.Management.dll). There are various properties available in the ManagementObject object that is accessed from the ManagementObjectSearcher.
There is a wealth of information available about the system hard drives by using these classes. This C# method will output all of those properties to the console:
//using System.Management; public static void OutputHddInformation() { // Create our WMI searcher to do our query ManagementObjectSearcher searcher = new ManagementObjectSearcher( "select * from Win32_DiskDrive" ); // Now loop through all the item found with the query int hdd = 1; foreach ( ManagementObject obj in searcher.Get() ) { Console.WriteLine( String.Format( "HDD #{0}:" , hdd ) ); // Now step through each of the properties and output their values foreach ( PropertyData property in obj.Properties ) { if ( property.Value != null ) { Console.WriteLine( property.Name + " = " + property.Value.ToString() ); } } Console.WriteLine( "---------------------------------" ); // Increment our hdd count hdd++; } // Wait for a keypress before continuting Console.WriteLine( "Press any key to continue..." ); Console.ReadKey(); }
On my computer that produces the following output:
HDD #1: BytesPerSector = 512 Capabilities = System.UInt16[] CapabilityDescriptions = System.String[] Caption = ST9500420AS ConfigManagerErrorCode = 0 ConfigManagerUserConfig = False CreationClassName = Win32_DiskDrive Description = Disk drive DeviceID = \\.\PHYSICALDRIVE0 FirmwareRevision = 0006 Index = 0 InterfaceType = IDE Manufacturer = (Standard disk drives) MediaLoaded = True MediaType = Fixed hard disk media Model = ST9500420AS Name = \\.\PHYSICALDRIVE0 Partitions = 4 PNPDeviceID = IDE\DISKST9500420AS__0006HPM1\4&8F6326A &0&0.0.0 SCSIBus = 0 SCSILogicalUnit = 0 SCSIPort = 0 SCSITargetId = 0 SectorsPerTrack = 63 SerialNumber = V55JYNGK Signature = 1105863606 Size = 500105249280 Status = OK SystemCreationClassName = Win32_ComputerSystem SystemName = MY_PC TotalCylinders = 60801 TotalHeads = 255 TotalSectors = 976768065 TotalTracks = 15504255 TracksPerCylinder = 255 --------------------------------- Press any key to continue...
Of course, not all of that information will work equally well for tracking system activation. Pick one or two pieces of information that are likely to only change when the HDD changes. For example, Model, TotalHeads, etc. but be alert to the possible existence of removable hard drives. If the InterfaceType property is USB or the MediaType property says something about it being an “External” device it should be excluded from being included as part of the hardware activation.
This C# method will return a string containing the Model properties for all of the internal HDD installed in the system:
//using System.Management; public static string GetHddInformation() { string hdd = String.Empty; // Create our WMI searcher to do our query ManagementObjectSearcher searcher = new ManagementObjectSearcher( "select * from Win32_DiskDrive" ); // Now loop through all the item found with the query foreach ( ManagementObject obj in searcher.Get() ) { object model = obj[ "Model" ]; object interfaceType = obj[ "InterfaceType" ]; object mediaType = obj[ "MediaType" ]; bool usb = ( interfaceType == null ? false : interfaceType.ToString().IndexOf( "USB" ) > -1 ); bool external = ( mediaType == null ? false : mediaType.ToString().IndexOf( "External" ) > -1 ); if ( ! usb && ! external && model != null ) { hdd += ( String.IsNullOrEmpty( hdd ) ? "" : " ~~ " ) + model.ToString().Trim(); } } return hdd; }
Remember that this should just be one piece of your activation strategy which needs to strike a good balance to provide a solid basis for software protection while being as invisible as possible for your customers trying to use your software.
In the next article I’ll discuss another piece of hardware information that can be used during software activation.