⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 如何获得硬盘序列号(2).htm

📁 如何获得硬盘序列号(2)
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0051)http://www3.ccw.com.cn/club/essence/200110/6642.htm -->
<HTML><HEAD><TITLE>如何获得硬盘序列号(2)</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY>
<P style="FONT-SIZE: 26px; FONT-WEIGHT: bold">如何获得硬盘序列号(2)</P>
<P style="FONT-SIZE: 18px; FONT-WEIGHT: bold; TEXT-INDENT: 20px">cyberghost</P>
<P style="FONT-SIZE: 12px; TEXT-ALIGN: right">C、C++ (2001-10-30 12:39:18) 
<HR style="COLOR: #000000; HEIGHT: 1px">

<P></P>
<DIV 
style="FONT-SIZE: 12px">//============================================================= 
<BR>// DoIDENTIFY <BR>// FUNCTION: Send an IDENTIFY command to the drive <BR>// 
bDriveNum = 0-3 <BR>// bIDCmd = IDE_ATA_IDENTIFY or IDE_ATAPI_IDENTIFY 
<BR>//============================================================== 
<BR>#define&nbsp;&nbsp;SENDIDLENGTH&nbsp;&nbsp;sizeof (SENDCMDOUTPARAMS) + 
IDENTIFY_BUFFER_SIZE <BR><BR>BOOL ReadIdeDriveAsScsiDriveInNT(void) <BR>{ 
<BR>BOOL bRet = FALSE; <BR>int controller = 0; <BR><BR>HANDLE hScsiDriveIOCTL = 
0; <BR>char&nbsp;&nbsp;&nbsp;driveName [256]; <BR><BR>// Try to get a handle to 
PhysicalDrive IOCTL, report failure <BR>// and exit if can't. <BR>sprintf 
(driveName, "\\\\.\\Scsi%d:", controller); <BR><BR>// Windows NT, Windows 2000, 
any rights should do <BR>hScsiDriveIOCTL = CreateFile( driveName <BR>, 
GENERIC_READ | GENERIC_WRITE <BR>, FILE_SHARE_READ | FILE_SHARE_WRITE <BR>, NULL 
<BR>, OPEN_EXISTING <BR>, 0 <BR>, NULL <BR>); <BR><BR>// if (hScsiDriveIOCTL == 
INVALID_HANDLE_VALUE) <BR>// printf ("Unable to open SCSI controller %d, error 
code: 0x%lX\n", 
<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;controller, 
GetLastError ()); <BR><BR>if (hScsiDriveIOCTL != INVALID_HANDLE_VALUE) <BR>{ 
<BR>int drive = 0; <BR><BR>char buffer[sizeof (SRB_IO_CONTROL) + SENDIDLENGTH]; 
<BR>SRB_IO_CONTROL *p = (SRB_IO_CONTROL *) buffer; <BR>SENDCMDINPARAMS *pin = 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(SENDCMDINPARAMS 
*) (buffer + sizeof (SRB_IO_CONTROL)); <BR>DWORD dummy; 
<BR>&nbsp;&nbsp;&nbsp;<BR>memset(buffer, 0, sizeof (buffer)); 
<BR>p-&gt;HeaderLength = sizeof (SRB_IO_CONTROL); <BR>p-&gt;Timeout = 10000; 
<BR>p-&gt;Length = SENDIDLENGTH; <BR>p-&gt;ControlCode = 
IOCTL_SCSI_MINIPORT_IDENTIFY; <BR>strncpy((char *) p-&gt;Signature, "SCSIDISK", 
8); <BR>&nbsp;&nbsp;<BR>pin-&gt;irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY; 
<BR>pin-&gt;bDriveNumber = drive; <BR><BR>if( DeviceIoControl( hScsiDriveIOCTL 
<BR>&nbsp;&nbsp;&nbsp;, IOCTL_SCSI_MINIPORT <BR>&nbsp;&nbsp;&nbsp;, buffer 
<BR>&nbsp;&nbsp;&nbsp;, sizeof(SRB_IO_CONTROL) + 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sizeof 
(SENDCMDINPARAMS) - 1 <BR>&nbsp;&nbsp;&nbsp;, buffer <BR>&nbsp;&nbsp;&nbsp;, 
sizeof (SRB_IO_CONTROL) + <BR>SENDIDLENGTH <BR>&nbsp;&nbsp;&nbsp;, &amp;dummy 
<BR>&nbsp;&nbsp;&nbsp;, NULL <BR>&nbsp;&nbsp;) <BR>&nbsp;&nbsp;) <BR>{ 
<BR>SENDCMDOUTPARAMS *pOut = 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(SENDCMDOUTPARAMS 
*) (buffer + sizeof (SRB_IO_CONTROL)); <BR>IDSECTOR *pId = (IDSECTOR 
*)(pOut-&gt;bBuffer); <BR>if( pId-&gt;sModelNumber [0] ) <BR>{ 
<BR>memset(diskData, 0, 1024); <BR>int i = 0; <BR>USHORT *pIdSector = (USHORT 
*)pId; <BR><BR>for( i = 0; i &lt; 256; i++ ) <BR>diskData[i] = pIdSector[i]; 
<BR><BR>bRet = TRUE; <BR>} <BR>} <BR>CloseHandle (hScsiDriveIOCTL); <BR>} 
<BR><BR>return bRet; <BR>} <BR><BR>char *ConvertToString( DWORD diskData[256] 
<BR>, int firstIndex <BR>, int lastIndex <BR>) <BR>{ <BR>static char string 
[1024]; <BR>int index = 0; <BR>int position = 0; <BR><BR>// each integer has two 
characters stored in it backwards <BR>for( index = firstIndex; index &lt;= 
lastIndex; index++ ) <BR>{ <BR>//&nbsp;&nbsp;get high byte for 1st character 
<BR>string[position] = (char)(diskData[index] / 256); <BR>position++; <BR><BR>// 
get low byte for 2nd character <BR>string[position] = (char)(diskData[index] % 
256); <BR>position++; <BR>} <BR><BR>// end the string <BR>string[position] = 
'\0'; <BR><BR>// cut off the trailing blanks <BR>for(index = position-1; index 
&gt;= 0; index--){ <BR>if(string[index]!=' ') break; 
<BR>else&nbsp;&nbsp;string[index]=0; <BR>} <BR>for(index = 0; index &lt; 
position; index++) <BR>if(string[index]!=' ') break; <BR>if(index!=0){ 
<BR>strncpy(string,string+index,position-index); <BR>string[position-index]=0; 
<BR>} <BR><BR>return string; <BR>} <BR><BR>BOOL GetHDSerialCode(char* 
lpSerialID) <BR>{ <BR>if( lpSerialID == NULL ) <BR>return FALSE; 
<BR><BR>memset(strHDSerialNumber, 0, 1024); <BR><BR>BOOL bRet; <BR><BR>bRet = 
ReadPhysicalDriveInNT(); <BR><BR>if( !bRet ) <BR>bRet = 
ReadIdeDriveAsScsiDriveInNT(); <BR><BR>if( bRet ) <BR>{ <BR>strcpy( 
strHDSerialNumber <BR>&nbsp;&nbsp;, ConvertToString(diskData, 10, 19) 
<BR>&nbsp;&nbsp;); <BR><BR>try <BR>{ <BR>strcpy(lpSerialID, strHDSerialNumber); 
<BR>} <BR>catch(...) <BR>{ <BR>return FALSE; <BR>} <BR>} <BR><BR>return bRet; 
<BR>} <BR><BR>void main(void) <BR>{ <BR>char strSerialNumber[16]; 
<BR>memset(strSerialNumber, 0, 16); <BR><BR>BOOL bRet = 
GetHDSerialCode(strSerialNumber); <BR><BR>if( bRet ) 
<BR>printf("SerialNumber=%s\n",strSerialNumber); <BR>} <BR><BR><BR></DIV>
<P>
<HR style="COLOR: #000000; HEIGHT: 1px">

<DIV style="FONT-SIZE: 12px; TEXT-ALIGN: right">i社区原文:<A 
href="http://www3.ccw.com.cn/club/bbs/bbsView.asp?essenceID=6642" 
target=_blank>如何获得硬盘序列号(2)</A></DIV>
<P></P></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -