Read the serial number of the hard disk with the API function
When we write a program, we want to generate a unique identifier for each computer, and we also see in this sharing software. Software has different identities on different machines. How is this implementation? Some software has some of the program reads, some of the hardware parameters of the local computer (such as hard disk serial number, network card serial number, etc.), and then get a unique identifier through a series of algorithms, in fact, we can also generate us through an API function. The only identifier, because the hard disk everyone has, and the NIC does not necessarily everyone, so take the hard disk serial number as an example, let's introduce the API function BOOL GetVolumeInformation (lpctstr lprootpathname, // hard disk this flag is a path LPTSTR lpVolumeNameBuffer, // disk label DWORD nVolumeNameSize, // label string length LPDWORD lpVolumeSerialNumber, // the hard disk serial number LPDWORD lpMaximumComponentLength, // maximum file size LPDWORD lpFileSystemFlags, // file system LPTSTR LPFILESYSTEMNAMEBUFFER, // Stores the length of the partition type of the partition type of the drive letter DWORD NFILESTEMNAMESIZE / / The length of the length of the long finger variable points to the partition type; if the above function is successful, a non-zero value is returned.
Light said that it is not done, we have to practice: // The largest file length is preferred to build a Dialog Base-based dialog project with MFC AppWizard, named Gethardid, click Finish. Add a button, double-click it, click OK, and add the following code in the corresponding function: lpctstr lprootpathname = "c: //"; // Take the C: = new char [12]; // Disk volume DWORD NVolumenameSize = 12; // Volume String String Length DWORD VOLUMESERIALNUMBER; / / Hard disk serial number DWORD MAXIMUMComponentLength; // The largest file length lptstr lpfilesystemnamebuffer = new char [10]; // Store the partition type of the partition type of the district DWORD nFileSystemNameSize = 10; // pointer partition type of variable length string pointed DWORD FileSystemFlags; // this flag is a file system :: GetVolumeInformation (lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize, & VolumeSerialNumber, & MaximumComponentLength, & FileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize) CSTRING STR; Str.Format ("Seria Num IS% LX", VolumeSerialNumber; AFXMessageBox (STR); Compilation, Link, and Run the program, click the button, in the pop-up dialog, the serial number we want. Don't verify us, enter the DOS window, to enter the "DIR C: / P" command, how is it like this is the same as our program display, we will get it.