Getvolumeinformation Get disk information and deviceiocontrol get hard disk Information

Source: Internet
Author: User

Hard Disk serial number: hard disk serial number, which is set by the manufacturer for different products at the time of factory delivery. It is unique and read-only, encryption By hard disk serial numbers often utilizes its unique and read-only features. Most of them are for ide hdd with serial numbers, and there is nothing to do with serial numbers or scsi hdd hard disks, this is also the limitation of using it for encryption.

Volume serial number: the English name of volume serial number. This number can be obtained from a disk, for example, a: disk and B: disk, or a logical disk, for example, C :, D :... it is randomly generated during advanced formatting and can be modified. Therefore, the uniqueness of the encryption can be improved, and its modification can be greatly reduced for security.

To obtain the disk serial number, volume label, and other information, call the getvolumeinformation API function. The function declaration is as follows:
Bool getvolumeinformation (
Lpctstr lprootpathname, // address of root directory of
// File System
Lptstr lpvolumenamebuffer, // address of name of the volume
DWORD nvolumenamesize, // length of lpvolumenamebuffer
Lpdword lpvolumeserialnumber, // address of volume serial number
Lpdword lpmaximumcomponentlength,
// Address of system's maximum
// Filename Length
Lpdword lpfilesystemflags, // address of file system flags
Lptstr lpfilesystemnamebuffer, // address of name of File System
DWORD nfilesystemnamesize // length of lpfilesystemnamebuffer
);

[VB]
Public declare function getvolumeinformation & lib "Kernel32" alias "Ge
Tvolumeinformationa "(byval lprootpathname as string, byval pvolumenam
Ebuffer as string, byval nvolumenamesize as long, lpvolumeserialnumber
As long, lpmaximumcomponentlength as long, lpfilesystemflags as long,
Byval lpfilesystemnamebuffer as string, byval nfilesystemnamesize
Long)

Using the API function getvolumeinformation to get the serial number of the hard disk !!! Let's look at the English version: volumeserialnumber! Only the serial number of the volume area is obtained!

The serial number of the hard disk should be
Drive model number ________________: WDC WD400EB-00CPF0
Drive serial number _______________: WD-WCAATF083586
Drive Controller revision number __: 06.04g06
Controller buffer size on drive ___: 2097152 bytes
Drive Type ____________________: fixed
Drive size ____________________: 40020664320 bytes
Medium:

Drive serial number _______________: WD-WCAATF083586 this is the hard drive serial number !!!!

This number will not be changed because you have formatted the hard disk, nor can it be changed by the tools circulating on the Internet. (In fact, the tools circulating on the Internet are only the volume area number. It's really a bit of a joke !)

The hard disk serial number is different from the disk serial number. The disk serial number is the volume (volumn) in the hard disk partition, that is, the serial number of the disk. The hard disk serial number is the serial number of the entire hard disk and cannot be modified.

 

 

 

-----------------------

Deviceiocontrol can be used to obtain the serial number of a hard disk. In fact, csdn is now available. Excerpt

Byte idoutcmd [sizeof (sendcmdoutparams) + identify_buffer_size-1];
Bool bflag = false;
Int drive = 0;
Char drivename [256];
Handle hphysicaldriveioctl = 0;

Sprintf (drivename, "\\\\. \ physicaldrive % d", drive );
// Administrator privilege is required to create a file in Windows NT/2000/XP
Hphysicaldriveioctl = createfile (drivename,
Generic_read | generic_write,
File_cmd_read | file_cmd_write, null,
Open_existing, 0, null );

If (hphysicaldriveioctl! = Invalid_handle_value)
{
Getversionoutparams versionparams;
DWORD cbbytesreturned = 0;

// Obtain the I/O controller version of the drive.
Memset (void *) & versionparams, 0, sizeof (versionparams ));
If (deviceiocontrol (hphysicaldriveioctl, ioctl_get_version,
Null, 0, & versionparams,
Sizeof (versionparams ),
& Cbbytesreturned, null ))
{
If (versionparams. bidedevicemap> 0)
{
Byte bidcmd = 0; // ide or atapi recognition command
Sendcmdinparams Scip;
 
// If the drive is an optical drive, run ide_atapi_identify, command,
// Otherwise, run ide_ata_identify to read the drive information.
Bidcmd = (versionparams. bidedevicemap> Drive & 0x10 )?
Ide_atapi_identify: ide_ata_identify;

Memset (& Scip, 0, sizeof (SCIP ));
Memset (idoutcmd, 0, sizeof (idoutcmd ));
// Obtain the drive information
If (winntgetidehdinfo (hphysicaldriveioctl,
& Scip,
(Psendcmdoutparams) & idoutcmd,
(Byte) bidcmd,
(Byte) Drive,
& Cbbytesreturned ))
{
Int m = 0;
Ushort * pidsector = (ushort *)
(Psendcmdoutparams) idoutcmd)-> bbuffer;

For (m = 0; m <256; m ++)
Buffer [m] = pidsector [m];
Bflag = true; // the hard disk information is read successfully.
}
}
}
Closehandle (hphysicaldriveioctl); // close the handle
}
Return bflag;

 

 

 

 

Bool cgethdserial: winntgetidehdinfo (handle hphysicaldriveioctl, psendcmdinparams pscip,
Psendcmdoutparams pscop, byte bidcmd, byte bdrivenum,
Pdword lpcbbytesreturned)
{
// Prepare parameters for reading device information
Pscip-> cbuffersize = identify_buffer_size;
Pscip-> irdriveregs. bfeaturesreg = 0;
Pscip-> irdriveregs. bsectorcounreg = 1;
Pscip-> irdriveregs. bsectornumberreg = 1;
Pscip-> irdriveregs. bcyllowreg = 0;
Pscip-> irdriveregs. bcylhighreg = 0;

// Calculate the drive position
Pscip-> irdriveregs. bdriveheadreg = 0xa0 | (bdrivenum & 1) <4 );

// Set the READ command
Pscip-> irdriveregs. bcommandreg = bidcmd;
Pscip-> bdrivenumber = bdrivenum;
Pscip-> cbuffersize = identify_buffer_size;

// Read the drive information
Return (deviceiocontrol (hphysicaldriveioctl, ioctl_get_drive_info,
(Lpvoid) pscip,
Sizeof (sendcmdinparams)-1,
(Lpvoid) pscop,
Sizeof (sendcmdoutparams) + identify_buffer_size-1,
Lpcbbytesreturned, null ));
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.