当前位置:首页 > 物理作业 > 正文
文章正文

查看硬盘序列号 获取硬盘物理序列号

物理作业 > :查看硬盘序列号 获取硬盘物理序列号是由作业高手网(www.solandy.net)为您精心收集,如果觉得好,请把这篇文章复制到您的博客或告诉您的朋友,以下是查看硬盘序列号 获取硬盘物理序列号的正文:

查看硬盘序列号(篇一)

获取硬盘物理序列号

获取硬盘物理序列号

最近才做完了这个获取 IDE 硬盘物理序列号的程序。声明一下,这个程序是我根据 Lynn McGuire 的那个 DiskID32 的源代码做了些自以为是的改动得到的,只能在 NT 平台下获得第一块 IDE 硬盘的物理序列号。同时,这个程序用到了不少未公开的 Windows 的结构和常量......

下面就是相应的 C++ 代码,在 XP SP2 + VC 2005 Express 下调试通过。

void GetDiskPhysicalSN(char pchDiskPhysicalSN[14])

{

BYTE IdOutCmd[530];

HANDLE drive=CreateFile (L"////.//PhysicalDrive0", GENERIC_READ |

GENERIC_WRITE,

FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,

OPEN_EXISTING, 0, NULL);

if (drive == INVALID_HANDLE_VALUE)

{

// 错误处理

return ;

}

GETVERSIONOUTPARAMS VersionParams;

DWORD cbBytesReturned = 0;

memset ((void*) &VersionParams, 0, sizeof(VersionParams));

if (!DeviceIoControl(drive, DFP_GET_VERSION, NULL, 0,

&VersionParams,

sizeof

(VersionParams), &cbBytesReturned, NULL))

{

// 错误处理

return ;

}

if (VersionParams.bIDEDeviceMap<=0)

{

// 错误处理

return ;

}

BYTE bIDCmd = 0;

SENDCMDINPARAMS scip;

bIDCmd = (VersionParams.bIDEDeviceMap >> 0 & 0x10) ?

IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY;

memset (&scip, 0, sizeof(scip));

memset (IdOutCmd, 0, sizeof(IdOutCmd));

scip.cBufferSize=IDENTIFY_BUFFER_SIZE;

scip.irDriveRegs.bFeaturesReg=0;

scip.irDriveRegs.bSectorCountReg=1;

scip.irDriveRegs.bSectorNumberReg=1;

scip.irDriveRegs.bCylLowReg=0;

scip.irDriveRegs.bCylHighReg=0;

scip.irDriveRegs.bDriveHeadReg=0xA0 | (((BYTE) drive & 1) << 4);

scip.irDriveRegs.bCommandReg=bIDCmd;

scip.bDriveNumber=(BYTE) drive;

scip.cBufferSize=IDENTIFY_BUFFER_SIZE;

if (!DeviceIoControl(drive, DFP_RECEIVE_DRIVE_DATA, &scip, sizeof

(SENDCMDINPARAMS) - 1,

(LPVOID)&IdOutCmd,

sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1,

&cbBytesReturned,

NULL))

{

// 错误处理

return ;

}

USHORT *pIdSector = (USHORT *)((PSENDCMDOUTPARAMS) IdOutCmd) ->

bBuffer;

int nIndex=0, nPosition=0;

for (nIndex=13; nIndex<20; nIndex++)

{

pchDiskPhysicalSN[nPosition++]=(unsigned char)(pIdSector

[nIndex]/256);

pchDiskPhysicalSN[nPosition++]=(unsigned char)(pIdSector

[nIndex]%256);

}

}

需要自定义的常量和结构为:

// IOCTL 指令常数

#define DFP_GET_VERSION 0x00074080

#define DFP_RECEIVE_DRIVE_DATA 0x0007c088

// 用于 IDEREGS 结构 bCommandReg 项的有效值

#define IDE_ATAPI_IDENTIFY 0xA1

#define IDE_ATA_IDENTIFY 0xEC

#define IDENTIFY_BUFFER_SIZE 512

// 结构体定义

// 保存磁盘驱动器的信息

typedef struct _GETVERSIONOUTPARAMS

{

BYTE bVersion;

BYTE bRevision;

BYTE bReserved;

BYTE bIDEDeviceMap;

DWORD fCapabilities;

DWORD dwReserved[4];

} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS;

// IDE 寄存器

typedef struct _IDEREGS

{

BYTE bFeaturesReg;

BYTE bSectorCountReg;

BYTE bSectorNumberReg;

BYTE bCylLowReg;

BYTE bCylHighReg;

BYTE bDriveHeadReg;

BYTE bCommandReg;

BYTE bReserved;

} IDEREGS, *PIDEREGS, *LPIDEREGS;

// 发送磁盘指令的输入参数

typedef struct _SENDCMDINPARAMS

{查看硬盘序列号}.

{

DWORD cBufferSize;

IDEREGS irDriveRegs;

BYTE bDriveNumber;

BYTE bReserved[3];

DWORD dwReserved[4];

BYTE bBuffer[1];

} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS; // 磁盘状态

typedef struct _DRIVERSTATUS

{

BYTE bDriverError;

BYTE bIDEStatus;

BYTE bReserved[2];

DWORD dwReserved[2];

} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS;

// 发送磁盘指令的输出参数

typedef struct _SENDCMDOUTPARAMS

{

DWORD cBufferSize;

DRIVERSTATUS DriverStatus;

BYTE bBuffer[1];

} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS;

同时,还需要提醒的是,这个程序需要用到头文件 Iphlpapi.h,并需要将 Iphlpapi.lib 包含在连接器的库文件参数下。

其中很多的细节我还搞得不是特别清楚,该死的微软,那么多的好东西都不公开......

查看硬盘序列号(篇二)

获取硬盘序列号

用api函数读取硬盘的序列号

关于盘序列号有两种:

硬盘序列号: 英文名 Hard Disk Serial Number, 该号是出厂时生产厂家为

区别产品而设置的, 是唯一的, 是只读的, 利用硬盘序列号的

加密往往是利用其唯一和只读的特性, 大多是针对有序列号的

IDE HDD而言, 对于没有序列号或SCSI HDD硬盘则无能为力,

这也是利用它进行加密的局限性.

卷的序列号: 英文名 Volume Serial Number, 该号既可指软磁盘要得, 如:

A:盘和B:盘的, 又可以指硬盘的逻辑盘, 如: C:, D:...的,

是高级格式化时随机产生的, 是可以修改的, 所以利用其进行

加密,

在写程序时我们想对每一台计算机都生成一个唯一的标识,而且在一此共享软件中我们也看到,软件在不同的机器上生成了不同的标识,这是如何实现的呢,其实是软件有一部分程序读取了,本地计算机的一部分硬件参数(如硬盘序列号,网卡序列号等等),再通过一系列算法而得到了一个唯一标识,其实我们也可以通过一个api函数生成我们的唯一标识,由于硬盘人人都有,而网卡不一定每个人都有,所以以读硬盘序列号为例,{查看硬盘序列号}.

下面就先介绍一下我们要用到的api函数

BOOL GetVolumeInformation(

LPCTSTR lpRootPathName, // 硬盘的路径

LPTSTR lpVolumeNameBuffer, // 硬盘的卷标

DWORD nVolumeNameSize, // 卷标的字符串长度{查看硬盘序列号}.

LPDWORD lpVolumeSerialNumber, // 硬盘的序列号

LPDWORD lpMaximumComponentLength, // 最大的文件长度

LPDWORD lpFileSystemFlags, // 文件系统的一此标志

LPTSTR lpFileSystemNameBuffer, // 存储所在盘符的分区类型的长指针变量 DWORD nFileSystemNameSize // 分区类型的长指针变量所指向的字符串长度

);

如果上述函数成功就返回一个非0值。

光说不做,是不行了,我们还得实践一下:// 最大的文件长度

首选用MFC AppWizard建立一个基于Dialog base的对话框工程,名为GetHardID,点击finish。

加一个按钮,双击它,点击ok,并在对应的函数中加入如下代码:

LPCTSTR lpRootPathName="c:\\"; //取C盘

LPTSTR lpVolumeNameBuffer=new char[12];//磁盘卷标

DWORD nVolumeNameSize=12;// 卷标的字符串长度

DWORD VolumeSerialNumber;//硬盘序列号

DWORD MaximumComponentLength;// 最大的文件长度

LPTSTR lpFileSystemNameBuffer=new char[10];// 存储所在盘符的分区类型的长

指针变量

DWORD nFileSystemNameSize=10;// 分区类型的长指针变量所指向的字符串长度 DWORD FileSystemFlags;// 文件系统的一此标志

::GetVolumeInformation(lpRootPathName,

lpVolumeNameBuffer, nVolumeNameSize,

&VolumeSerialNumber, &MaximumComponentLength,

&FileSystemFlags,

lpFileSystemNameBuffer, nFileSystemNameSize);

CString str;

str.Format("Seria Num is %lx ",VolumeSerialNumber);

AfxMessageBox(str);

编译,链接并运行程序,单击按钮,在弹出的对话框中就是我们要的序列号。

对不对我们验证一下,进入dos窗口,打入"dir c:/p"命令,怎么样是不是和我们的程序显示的一模一样

这样我们就在功告成了。

=======cpu adapter id ===========

以下代码可以取得系统特征码(网卡MAC、硬盘序列号、CPU ID、BIOS编号) BYTE szSystemInfo[4096]; // 在程序执行完毕后,此处存储取得的系统特征码 UINT uSystemInfoLen = 0; // 在程序执行完毕后,此处存储取得的系统特征码的长度

// 网卡 MAC 地址,注意: MAC 地址是可以在注册表

{

UINT uErrorCode = 0;

IP_ADAPTER_INFO iai;

ULONG uSize = 0;

DWORD dwResult = GetAdaptersInfo( &iai, &uSize );

if( dwResult == ERROR_BUFFER_OVERFLOW )

{

IP_ADAPTER_INFO* piai =

( IP_ADAPTER_INFO* )HeapAlloc( GetProcessHeap( ), 0, uSize );

if( piai != NULL )

{

{查看硬盘序列号}.

dwResult = GetAdaptersInfo( piai, &uSize );

if( ERROR_SUCCESS == dwResult )

{

IP_ADAPTER_INFO* piai2 = piai;

while( piai2 != NULL && ( uSystemInfoLen +

piai2->AddressLength ) < 4096U )

{

CopyMemory( szSystemInfo + uSystemInfoLen,

piai2->Address, piai2->AddressLength );

uSystemInfoLen += piai2->AddressLength;

piai2 = piai2->Next;

}

}

else

{

uErrorCode = 0xF0000000U + dwResult;

}

VERIFY( HeapFree( GetProcessHeap( ), 0, piai ) );

}

else

{

return FALSE;

}

}

else

{

uErrorCode = 0xE0000000U + dwResult;

}

if( uErrorCode != 0U )

{

return FALSE;

}

}

// 硬盘序列号,注意:有的硬盘没有序列号

{

OSVERSIONINFO ovi = { 0 };

ovi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );{查看硬盘序列号}.

GetVersionEx( &ovi );

if( ovi.dwPlatformId != VER_PLATFORM_WIN32_NT )

{

// Only return FALSE;

}

else

{

if( !WinNTHDSerialNum&uSystemInfoLen, 1024 ) )

{

WinNTHDSerialNumAsScsiRead( szSystemInfo, &uSystemInfoLen, 1024 );

}

}

}

// CPU ID

{

BOOL bException = FALSE;

BYTE szCpu[16] = { 0 };

UINT uCpuID = 0U;

__try

{

_asm

{

mov eax, 0

cpuid

mov dword ptr szCpu[0], ebx

mov dword ptr szCpu[4], edx

mov dword ptr szCpu[8], ecx

mov eax, 1

cpuid

mov uCpuID, edx

}

}

__except( EXCEPTION_EXECUTE_HANDLER )

{

bException = TRUE;

}

if( !bException )

{

CopyMemory( szSystemInfo + uSystemInfoLen, &uCpuID,

sizeof( UINT ) );

uSystemInfoLen += sizeof( UINT );

uCpuID = strlen( ( char* )szCpu );

CopyMemory( szSystemInfo + uSystemInfoLen, szCpu, uCpuID ); uSystemInfoLen += uCpuID;

}

}

// BIOS 编号,支持 AMI, AWARD, PHOENIX

{

SIZE_T ssize;

LARGE_INTEGER so;

so.LowPart=0x000f0000;

so.HighPart=0x00000000;

ssize=0xffff;

wchar_t strPH[30]=L\\device\\physicalmemory;

DWORD ba=0;

UNICODE_STRING struniph;

struniph.Buffer=strPH;

struniph.Length=0x2c;

struniph.Maximength =0x2e;

OBJECT_ATTRIBUTES obj_ar;

obj_ar.Attributes =64;

obj_ar.Length =24;

obj_ar.ObjectName=&struniph;

obj_ar.RootDirectory=0;

obj_ar.SecurityDescriptor=0;

obj_ar.SecurityQualityOfService =0;

HMODULE hinstLib = LoadLibrary("ntdll.dll");

ZWOS ZWopenS=(ZWOS)GetProcAddress(hinstLib,"ZwOpenSection"); ZWMV

ZWmapV=(ZWMV)GetProcAddress(hinstLib,"ZwMapViewOfSection"); ZWUMV

ZWunmapV=(ZWUMV)GetProcAddress(hinstLib,"ZwUnmapViewOfSection");

//调用函数,对物理内存进行映射

HANDLE hSection;

if( 0 == ZWopenS(&hSection,4,&obj_ar) &&

0 == ZWmapV(

( HANDLE )hSection, //打开Section时得到的句柄

( HANDLE )0xFFFFFFFF, //将要映射进程的句柄,

&ba, //映射的基址

0,

0xFFFF, //分配的大小

&so, //物理内存的地址

&ssize, //指向读取内存块大小的指针

1, //子进程的可继承性设定

0, //分配类型

2 //保护类型

) )

//执行后会在当前进程的空间开辟一段64k的空间,并把f000:0000到f000:ffff处的内容映射到这里

//映射的基址由ba返回,如果映射不再有用,应该用ZwUnmapViewOfSection断

查看硬盘序列号(篇三)

获取硬盘序列号的代码{查看硬盘序列号}.

网上有很多获取硬盘序列号的代码,但大部分都只能取得逻辑分区的序列号,而不能取得硬盘的物理序列号。我们知道,逻辑分区的序列号是FORMAT时产生的,重新FORMAT将会改变。这对于要求唯一识别码的程式来说是致命的。这段代码利用API可以取得物理硬盘的很多特性,包括硬盘出厂时的唯一编号。这段代码我是从CSDN论坛获得,原作者不详。我将其稍做修改和增添,独立出两个常用的函数:GetDiskVolume 、GetHardDiskInfo ......'============================================'模块功能: 取得硬盘的信息'编 程:来自互联网,阿勇修改'更新日期:2005/7/8'调用方法:' GetDiskVolume() 取得逻辑盘的序列号' GetHardDiskInfo() 取得物理盘的型号或序列号'============================================Private Const MAX_IDE_DRIVES As Long = 4 ' Max number of drives assuming primary/secondary, master/slave topologyPrivate Const READ_ATTRIBUTE_BUFFER_SIZE As Long = 512Private Const IDENTIFY_BUFFER_SIZE As Long = 512Private Const READ_THRESHOLD_BUFFER_SIZE As Long = 512Private Const DFP_GET_VERSION As Long = &H74080Private Const DFP_SEND_DRIVE_COMMAND As Long = &H7C084Private Const DFP_RECEIVE_DRIVE_DATA As Long = &H7C088Private Type GETVERSIONOUTPARAMSbVersion As Byte ' Binary driver version.bRevision As Byte ' Binary driver revision.bReserved As Byte ' Not used.bIDEDeviceMap As Byte ' Bit map of IDE devices.fCapabilities As Long ' Bit mask of driver capabilities.dwReserved(3) As Long ' For future use.End TypePrivate Const CAP_IDE_ID_FUNCTION As Long = 1 ' ATA ID command supportedPrivate Const CAP_IDE_ATAPI_ID As Long = 2 ' ATAPI ID command supportedPrivate Const CAP_IDE_EXECUTE_SMART_FUNCTION As Long = 4 ' SMART commannds supportedPrivate Type IDEREGSbFeaturesReg As Byte ' Used for specifying SMART "commands".bSectorCountReg As Byte ' IDE sector count registerbSectorNumberReg As Byte ' IDE sector number registerbCylLowReg As Byte ' IDE low order cylinder valuebCylHighReg As Byte ' IDE high order cylinder valuebDriveHeadReg As Byte ' IDE drive/head registerbCommandReg As Byte ' Actual IDE command.bReserved As Byte ' reserved for future use. Must be zero.End TypePrivate Type SENDCMDINPARAMScBufferSize As Long ' Buffer size in bytesirDriveRegs As IDEREGS ' Structure with drive register values.bDriveNumber As Byte ' Physical drive number to send' command to (0,1,2,3).bReserved(2) As Byte ' Reserved for future expansion.dwReserved(3) As Long ' For future use.bBuffer(0) As Byte ' Input buffer.End TypePrivate Const IDE_ATAPI_ID As Long = &HA1 ' Returns ID sector for ATAPI.

Private Const IDE_ID_FUNCTION As Long = &HEC ' Returns ID sector for ATA.Private Const IDE_EXECUTE_SMART_FUNCTION As Long = &HB0 ' Performs SMART cmd.Private Const SMART_CYL_LOW As Long = &H4FPrivate Const SMART_CYL_HI As Long = &HC2Private Type DRIVERSTATUSbDriverError As Byte ' Error code from driver,bIDEStatus As Byte ' Contents of IDE Error register.bReserved(1) As Byte ' Reserved for future expansion.dwReserved(1) As Long ' Reserved for future expansion.End TypePrivate Const SMART_NO_ERROR As Long = 0 ' No errorPrivate Const SMART_IDE_ERROR As Long = 1 ' Error from IDE controllerPrivate Const SMART_INVALID_FLAG As Long = 2 ' Invalid command flagPrivate Const SMART_INVALID_COMMAND As Long = 3 ' Invalid command bytePrivate Const SMART_INVALID_BUFFER As Long = 4 ' Bad buffer (null, invalid addr..)Private Const SMART_INVALID_DRIVE As Long = 5 ' Drive number not validPrivate Const SMART_INVALID_IOCTL As Long = 6 ' Invalid IOCTLPrivate Const SMART_ERROR_NO_MEM As Long = 7 ' Could not lock user's bufferPrivate Const SMART_INVALID_REGISTER As Long = 8 ' Some IDE Register not validPrivate Const SMART_NOT_SUPPORTED As Long = 9 ' Invalid cmd flag setPrivate Const SMART_NO_IDE_DEVICE As Long = 10 ' Cmd issued to device not presentPrivate Type SENDCMDOUTPARAMScBufferSize As Long ' Size of bBuffer in bytesdrvStatus As DRIVERSTATUS ' Driver status structure.bBuffer(0) As Byte ' Buffer of arbitrary length in which to store the data read from the ' drive.End TypePrivate Const SMART_READ_ATTRIBUTE_VALUES As Long = &HD0 ' ATA4: RenamedPrivate Const SMART_READ_ATTRIBUTE_THRESHOLDS As Long = &HD1 ' Obsoleted in ATA4!Private Const SMART_ENABLE_DISABLE_ATTRIBUTE_AUTOSAVE As Long = &HD2Private Const SMART_SAVE_ATTRIBUTE_VALUES As Long = &HD3Private Const SMART_EXECUTE_OFFLINE_IMMEDIATE As Long = &HD4 ' ATA4Private Const SMART_ENABLE_SMART_OPERATIONS As Long = &HD8Private Const SMART_DISABLE_SMART_OPERATIONS As Long = &HD9Private Const SMART_RETURN_SMART_STATUS As Long = &HDAPrivate Type DRIVEATTRIBUTEbAttrID As Byte ' Identifies which attributewStatusFlags As Integer ' see bit definitions belowbAttrValue As Byte ' Current normalized valuebWorstValue As Byte ' How bad has it ever been?bRawValue(5) As Byte ' Un-normalized valuebReserved As Byte ' ...End TypePrivate Type ATTRTHRESHOLDbAttrID As Byte ' Identifies which attributebWarrantyThreshold As Byte ' Triggering valuebReserved(9) As Byte ' ...End TypePrivate Type IDSECTORwGenConfig As IntegerwNumCyls As IntegerwReserved As IntegerwNumHeads As IntegerwBytesPerTrack As IntegerwBytesPerSector As IntegerwSectorsPerTrack As IntegerwVendorUnique(2) As Integer{查看硬盘序列号}.

sSerialNumber(19) As BytewBufferType As IntegerwBufferSize As IntegerwECCSize As IntegersFirmwareRev(7) As BytesModelNumber(39) As BytewMoreVendorUnique As IntegerwDoubleWordIO As IntegerwCapabilities As IntegerwReserved1 As IntegerwPIOTiming As IntegerwDMATiming As IntegerwBS As IntegerwNumCurrentCyls As IntegerwNumCurrentHeads As IntegerwNumCurrentSectorsPerTrack As IntegerulCurrentSectorCapacity(3) As Byte '这里只能用byte,因为VB没有无符号的LONG型变量wMultSectorStuff As IntegerulTotalAddressableSectors(3) As Byte '这里只能用byte,因为VB没有无符号的LONG型变量wSingleWordDMA As IntegerwMultiWordDMA As IntegerbReserved(127) As ByteEnd TypePrivate Const ATTR_INVALID As Long = 0Private Const ATTR_READ_ERROR_RATE As Long = 1Private Const ATTR_THROUGHPUT_PERF As Long = 2Private Const ATTR_SPIN_UP_TIME As Long = 3Private Const ATTR_START_STOP_COUNT As Long = 4Private Const ATTR_REALLOC_SECTOR_COUNT As Long = 5Private Const ATTR_READ_CHANNEL_MARGIN As Long = 6Private Const ATTR_SEEK_ERROR_RATE As Long = 7Private Const ATTR_SEEK_TIME_PERF As Long = 8Private Const ATTR_POWER_ON_HRS_COUNT As Long = 9Private Const ATTR_SPIN_RETRY_COUNT As Long = 10Private Const ATTR_CALIBRATION_RETRY_COUNT As Long = 11Private Const ATTR_POWER_CYCLE_COUNT As Long = 12Private Const PRE_FAILURE_WARRANTY As Long = &H1Private Const ON_LINE_COLLECTION As Long = &H2Private Const PERFORMANCE_ATTRIBUTE As Long = &H4Private Const ERROR_RATE_ATTRIBUTE As Long = &H8Private Const EVENT_COUNT_ATTRIBUTE As Long = &H10Private Const SELF_PRESERVING_ATTRIBUTE As Long = &H20Private Const NUM_ATTRIBUTE_STRUCTS As Long = 30Private Const INVALID_HANDLE_VALUE As Long = -1Private Const VER_PLATFORM_WIN32s As Long = 0Private Const VER_PLATFORM_WIN32_WINDOWS As Long = 1Private Const VER_PLATFORM_WIN32_NT As Long = 2Private Type OSVERSIONINFOdwOSVersionInfoSize As LongdwMajorVersion As LongdwMinorVersion As LongdwBuildNumber As LongdwPlatformId As LongszCSDVersion As String * 128 ' Maintenance string for PSS usageEnd TypePrivate Const CREATE_NEW As Long = 1Private Const GENERIC_READ As Long = &H80000000Private Const GENERIC_WRITE As Long = &H40000000Private Const FILE_SHARE_READ As Long = &H1Private Const FILE_SHARE_WRITE As Long = &H2Private Const OPEN_EXISTING As Long = 3Private m_DiskInfo As IDSECTORPrivate Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As LongPrivate Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As

Long) As LongPrivate Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As LongPrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long'信息类型枚举Enum eumInfoTypehdmodelsn = 0hdOnlyModel = 1hdOnlySN = 2End Enum'磁盘通道枚举Enum eumDiskNohdPrimaryMaster = 0hdPrimarySlave = 1hdSecondaryMaster = 2hdSecondarySlave = 3End Enum'取得逻辑盘序列号 (非唯一)Function GetDiskVolume(Optional ByVal strDiskName = "C") As StringDim TempStr1 As String * 256, TempStr2 As String * 256Dim TempLon1 As Long, TempLon2 As Long, GetVal As LongDim tmpVol As StringCall GetVolumeInformation(strDiskName & ":\", TempStr1, 256, GetVal, TempLon1, TempLon2, TempStr2, 256)If GetVal = 0 ThentmpVol = ""ElsetmpVol = Hex(GetVal)tmpVol = String(8 - Len(tmpVol), "0") & tmpVoltmpVol = Left(tmpVol, 4) & "-" & Right(tmpVol, 4)End IfGetDiskVolume = tmpVolEnd Function'取得硬盘信息:型号/物理系列号(唯一)Function GetHardDiskInfo(Optional ByVal numDisk As eumDiskNo = hdPrimaryMaster, Optional ByVal numType As eumInfoType = hdOnlySN) As StringIf GetDiskInfo(numDisk) = 1 ThenDim pSerialNumber As String, pModelNumber As StringpSerialNumber = StrConv(m_DiskInfo.sSerialNumber, vbUnicode)pModelNumber = StrConv(m_DiskInfo.sModelNumber, vbUnicode)Select Case numTypeCase hdOnlyModel '仅型号GetHardDiskInfo = Trim(pModelNumber)Case hdOnlySN '仅系列号GetHardDiskInfo = Trim(pSerialNumber)Case Else '型号,系列号GetHardDiskInfo = Trim(pModelNumber) & "," & Trim(pSerialNumber)End SelectEnd IfEnd FunctionPrivate Function OpenSMART(ByVal nDrive As Byte) As LongDim hSMARTIOCTL As LongDim hd As StringDim VersionInfo As OSVERSIONINFOhSMARTIOCTL = INVALID_HANDLE_VALUEVersionInfo.dwOSVersionInfoSize = Len(VersionInfo)GetVersionEx VersionInfoSelect Case VersionInfo.dwPlatformIdCase VER_PLATFORM_WIN32sOpenSMART = hSMARTIOCTLCase VER_PLAT

FORM_WIN32_WINDOWShSMARTIOCTL = CreateFile("\\.\SMARTVSD", 0, 0, 0, CREATE_NEW, 0, 0)Case VER_PLATFORM_WIN32_NTIf nDrive < MAX_IDE_DRIVES Thenhd = "\\.\PhysicalDrive" & nDrivehSMARTIOCTL = CreateFile(hd, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)End IfEnd SelectOpenSMART = hSMARTIOCTLEnd FunctionPrivate Function DoIDENTIFY(ByVal hSMARTIOCTL As Long, pSCIP As SENDCMDINPARAMS, pSCOP() As Byte, ByVal bIDCmd As Byte, ByVal bDriveNum As Byte, lpcbBytesReturned As Long) As BooleanpSCIP.cBufferSize = IDENTIFY_BUFFER_SIZEpSCIP.irDriveRegs.bFeaturesReg = 0pSCIP.irDriveRegs.bSectorCountReg = 1pSCIP.irDriveRegs.bSectorNumberReg = 1pSCIP.irDriveRegs.bCylLowReg = 0pSCIP.irDriveRegs.bCylHighReg = 0pSCIP.irDriveRegs.bDriveHeadReg = &HA0 Or ((bDriveNum And 1) * 2 ^ 4)'pSCIP.irDriveRegs.bCommandReg = bIDCmdpSCIP.bDriveNumber = bDriveNumpSCIP.cBufferSize = IDENTIFY_BUFFER_SIZEDoIDENTIFY = CBool(DeviceIoControl(hSMARTIOCTL, DFP_RECEIVE_DRIVE_DATA, _pSCIP, 32, _pSCOP(0), 528, _lpcbBytesReturned, 0))End FunctionPrivate Function DoEnableSMART(ByVal hSMARTIOCTL As Long, pSCIP As SENDCMDINPARAMS, pSCOP As SENDCMDOUTPARAMS, ByVal bDriveNum As Byte, lpcbBytesReturned As Long) As BooleanpSCIP.cBufferSize = 0pSCIP.irDriveRegs.bFeaturesReg = SMART_ENABLE_SMART_OPERATIONSpSCIP.irDriveRegs.bSectorCountReg = 1pSCIP.irDriveRegs.bSectorNumberReg = 1pSCIP.irDriveRegs.bCylLowReg = SMART_CYL_LOWpSCIP.irDriveRegs.bCylHighReg = SMART_CYL_HIpSCIP.irDriveRegs.bDriveHeadReg = &HA0 Or ((bDriveNum And 1) * 2 ^ 4)pSCIP.irDriveRegs.bCommandReg = IDE_EXECUTE_SMART_FUNCTIONpSCIP.bDriveNumber = bDriveNumDoEnableSMART = CBool(DeviceIoControl(hSMARTIOCTL, DFP_SEND_DRIVE_COMMAND, _pSCIP, LenB(pSCIP) - 1, _pSCOP, LenB(pSCOP) - 1, _lpcbBytesReturned, 0))End Function'---------------------------------------------------------------------'---------------------------------------------------------------------Private Sub ChangeByteOrder(szString() As Byte, ByVal uscStrSize As Integer)Dim i As IntegerDim bTemp As ByteFor i = 0 To uscStrSize - 1 Step 2bTemp = szString(i)szString(i) = szString(i + 1)szString(i + 1) = bTempNext iEnd SubPrivate Sub DisplayIdInfo(pids As IDSECTOR, pSCIP As SENDCMDINPARAMS, ByVal bIDCmd As Byte, ByVal bDfpDriveMap As Byte, ByVal bDriveNum As Byte)ChangeByteOrder pids.sModelNumber, UBound(pids.sModelNumber) + 1ChangeByteOrder pids.sFirmwareRev, UBound(pids.sFirmwareRev) + 1ChangeByteOrder pids.sSerialNumber, UBound(pids.sSerialNumber) + 1End SubPublic Function GetDiskInfo(ByVal n

查看硬盘序列号(篇四)

windows服务器查看硬件信息命令

一、查看内存信息(1)查看内存详细信息:gwmi -class win32_physicalmemory(2)查看内存列表信息wmicwmic:root\cli>memorychip get *(3)查看内存最大容量和插槽数量gwmi -class win32_physicalmemoryarraywmicwmic:root\cli>path Win32_PhysicalMemoryArray get MemoryDevices二、查看CPU信息(1) 查看CPU详细信息gwmi -class win32_proccessor(2) 查看物理CPU个数@(gwmi -class win32_processor).count三、查看序列号wmic bios get serialnumbergwmi -class win32_bios四、查看服务器型号wmic csproduct get name

查看硬盘序列号(篇五)

获取硬盘的物理地址编号,CPU序列号

unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Button1: TButton;Memo1: TMemo;Edit1: TEdit;Edit2: TEdit;Label1: TLabel;Label2: TLabel;Label3: TLabel;Label4: TLabel;Label5: TLabel;PValue: TLabel;FValue: TLabel;MValue: TLabel;SValue: TLabel;Button2: TButton;Edit3: TEdit;Button3: TButton;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure Button3Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}function GetIdeSerialNumber: pchar; //获取硬盘的出厂系列号;const IDENTIFY_BUFFER_SIZE = 512; type TIDERegs = packed record bFeaturesReg: BYTE; bSectorCountReg: BYTE; bSectorNumberReg: BYTE; bCylLowReg: BYTE;bCylHighReg: BYTE; bDriveHeadReg: BYTE; bCommandReg: BYTE; bReserved: BYTE; end; TSendCmdInParams = packed record cBufferSize: DWORD; irDriveRegs: TIDERegs; bDriveNumber: BYTE; bReserved: array[0..2] of Byte; dwReserved: array[0..3] of DWORD; bBuffer: array[0..0] of Byte; end; TIdSector = packed record wGenConfig: Word; wNumCyls: Word; wReserved: Word; wNumHeads: Word; wBytesPerTrack: Word; wBytesPerSector: Word; wSectorsPerTrack: Word; wVendorUnique: array[0..2] of Word; sSerialNumber: array[0..19] of CHAR; wBufferType: Word; wBufferSize: Word; wECCSize: Word; sFirmwareRev: array[0..7] of Char; sModelNumber: array[0..39] of Char; wMoreVendorUnique: Word; wDoubleWordIO: Word; wCapabilities: Word; wReserved1: Word; wPIOTiming: Word; wDMATiming: Word; wBS: Word; wNumCurrentCyls: Word; wNumCurrentHeads: Word; wNumCurrentSectorsPerTrack: Word; ulCurrentSectorCapacity: DWORD; wMultSectorStuff: Word; ulTotalAddressableSectors: DWORD; wSingleWordDMA: Word; wMultiWordDMA: Word; bReserved: array[0..127] of BYTE; end; PIdSector = ^TIdSector; TDriverStatus = packed record bDriverError:

Byte; bIDEStatus: Byte; bReserved: array[0..1] of Byte; dwReserved: array[0..1] of DWORD; end; TSendCmdOutParams = packed record cBufferSize: DWORD; DriverStatus: TDriverStatus; bBuffer: array[0..0] of BYTE; end; var hDevice: Thandle; cbBytesReturned: DWORD; SCIP: TSendCmdInParams; aIdOutCmd: array[0..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE-1)-1] of Byte; IdOutCmd: TSendCmdOutParams absolute aIdOutCmd; procedure ChangeByteOrder(var Data; Size: Integer); var ptr: Pchar; i: Integer; c: Char; begin ptr := @Data; for I := 0 to (Size shr 1) - 1 do begin c := ptr^; ptr^ := (ptr + 1)^; (ptr + 1)^ := c; Inc(ptr, 2); end; end; begin Result := ''; if SysUtils.Win32Platform = VER_PLATFORM_WIN32_NT then begin // Windows NT, Windows 2000 hDevice := CreateFile('\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); end else // Version Windows 95 OSR2, Windows 98 hDevice := CreateFile('\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0); if hDevice = INVALID_HANDLE_VALUE then Exit; try FillChar(SCIP, SizeOf(TSendCmdInParams) - 1, #0); FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #0); cbBytesReturned := 0; with SCIP do begin cBufferSize := IDENTIFY_BUFFER_SIZE; with irDriveRegs do begin bSectorCountReg := 1; bSectorNumberReg := 1; bDriveHeadReg := $A0; bCommandReg := $EC; end; end; if not DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - 1, @aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil) then Exit; finally CloseHandle(hDevice); end; with PIdSector(@IdOutCmd.bBuffer)^ do begin ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber)); (Pchar(@sSerialNumber) + SizeOf(sSerialNumber))^:= #0; Result := Pchar(@sSerialNumber);

end; end;const ID_BIT = $200000; // EFLAGS ID bit type TCPUID = array[1..4] of Longint; TVendor = array [0..11] of char; function IsCPUID_Available : Boolean; register; asm PUSHFD {direct access to flags no possible, only via stack} POP EAX {flags to EAX}MOV EDX,EAX {save current flags} XOR EAX,ID_BIT {not ID bit} PUSH EAX {onto stack} POPFD {from stack to flags, with not ID bit} PUSHFD {back to stack} POP EAX {get back to EAX} XOR EAX,EDX {check if ID bit affected} JZ @exit {no, CPUID not availavle} MOV AL,True {Result=True} @exit: end; function GetCPUID : TCPUID; assembler; register; asm PUSH EBX {Save affected register} PUSH EDI MOV EDI,EAX {@Resukt} MOV EAX,1 DW $A20F {CPUID Command} STOSD {CPUID[1]} MOV EAX,EBX STOSD {CPUID[2]} MOV EAX,ECX STOSD {CPUID[3]} MOV EAX,EDX STOSD {CPUID[4]} POP EDI {Restore registers} POP EBX end; function GetCPUVendor : TVendor; assembler; register; asm PUSH EBX {Save affected register} PUSH EDI MOV EDI,EAX {@Result (TVendor)} MOV EAX,0 DW $A20F {CPUID Command} MOV EAX,EBX XCHG EBX,ECX {save ECX result} MOV ECX,4 @1: STOSB SHR EAX,8 LOOP @1 MOV EAX,EDX MOV ECX,4 @2: STOSB SHR EAX,8 LOOP @2 MOV EAX,EBX MOV ECX,4 @3: STOSB SHR EAX,8 LOOP @3 POP EDI {Restore registers} POP EBX end; function GetIdeDiskSerialNumber: string;type TSrbIoControl = packed record HeaderLength: ULONG; Signature: array[0..7] of Char; Timeout: ULONG; ControlCode: ULONG; ReturnCode: ULONG; Length: ULONG; end; SRB_IO_CONTROL = TSrbIoControl; PSrbIoControl = ^TSrbIoControl; TIDERegs = packe

d record bFeaturesReg: Byte; // Used for specifying SMART "commands". bSectorCountReg: Byte; // IDE sector count register bSectorNumberReg: Byte; // IDE sector number register bCylLowReg: Byte; // IDE low order cylinder value bCylHighReg: Byte; // IDE high order cylinder value bDriveHeadReg: Byte; // IDE drive/head register bCommandReg: Byte; // Actual IDE command. bReserved: Byte; // reserved for future use. Must be zero. end; IDEREGS = TIDERegs; PIDERegs = ^TIDERegs; TSendCmdInParams = packed record cBufferSize: DWORD; // Buffer size in bytes irDriveRegs: TIDERegs; // Structure with drive register values. bDriveNumber: Byte; // Physical drive number to send command to (0,1,2,3). bReserved: array[0..2] of Byte; // Reserved for future expansion. dwReserved: array[0..3] of DWORD; // For future use. bBuffer: array[0..0] of Byte; // Input buffer. end; SENDCMDINPARAMS = TSendCmdInParams; PSendCmdInParams = ^TSendCmdInParams; TIdSector = packed record wGenConfig: Word; wNumCyls: Word; wReserved: Word; wNumHeads: Word; wBytesPerTrack: Word; wBytesPerSector: Word; wSectorsPerTrack: Word; wVendorUnique: array[0..2] of Word; sSerialNumber: array[0..19] of Char; wBufferType: Word; wBufferSize: Word; wECCSize: Word; sFirmwareRev: array[0..7] of Char; sModelNumber: array[0..39] of Char; wMoreVendorUnique: Word; wDoubleWordIO: Word; wCapabilities: Word; wReserved1: Word; wPIOTiming: Word; wDMATiming: Word; wBS: Word; wNumCurrentCyls: Word; wNumCurrentHeads: Word; wNumCurrentSectorsPerTrack: Word; ulCurrentSectorCapacity: ULONG; wMultSectorStuff: Word; ulTotalAddressableSectors: ULONG; wSingleWordDMA: Word; wMultiWordDMA: Word; bReserved: array[0..127] of Byte; end; PIdSector = ^TIdSector; const IDE_ID_FUNCTION = $EC; IDENTIFY_BUFFER_SIZE = 512; DFP_RECEIVE_DRIVE_DATA = $0007C088; IOCTL_SCSI_MINIPORT = $0004D008; IOCTL_SCSI_MINIPORT_IDENTIFY = $001B0501; DataSize = si

zeof(TSendCmdInParams) - 1 + IDENTIFY_BUFFER_SIZE; BufferSize = SizeOf(SRB_IO_CONTROL) + DataSize; W9xBufferSize = IDENTIFY_BUFFER_SIZE + 16; varhDevice: THandle;cbBytesReturned: DWORD; pInData: PSendCmdInParams; pOutData: Pointer; // PSendCmdInParams; Buffer: array[0..BufferSize - 1] of Byte; srbControl: TSrbIoControl absolute Buffer; procedure ChangeByteOrder(var Data; Size: Integer); var ptr: PChar; i: Integer; c: Char; begin ptr := @Data; for i := 0 to (Size shr 1) - 1 do begin c := ptr^; ptr^ := (ptr + 1)^; (ptr + 1)^ := c; Inc(ptr, 2); end; end; begin Result := ''; FillChar(Buffer, BufferSize, #0); if Win32Platform = VER_PLATFORM_WIN32_NT then begin // Windows NT, Windows 2000 // Get SCSI port handle hDevice := CreateFile('\\.\Scsi0:', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if hDevice = INVALID_HANDLE_VALUE then Exit; try srbControl.HeaderLength := SizeOf(SRB_IO_CONTROL); System.Move('SCSIDISK', srbControl.Signature, 8); srbControl.Timeout := 2; srbControl.Length := DataSize; srbControl.ControlCode := IOCTL_SCSI_MINIPORT_IDENTIFY; pInData := PSendCmdInParams(PChar(@Buffer) + SizeOf(SRB_IO_CONTROL)); pOutData := pInData; with pInData^ do begin cBufferSize := IDENTIFY_BUFFER_SIZE; bDriveNumber := 0; with irDriveRegs do begin bFeaturesReg := 0; bSectorCountReg := 1; bSectorNumberReg := 1; bCylLowReg := 0; bCylHighReg := 0; bDriveHeadReg := $A0; bCommandReg := IDE_ID_FUNCTION; end; end; if not DeviceIoControl(hDevice, IOCTL_SCSI_MINIPORT, @Buffer, BufferSize, @Buffer, BufferSize, cbBytesReturned, nil) then Exit; finally CloseHandle(hDevice); end; end else begin // Windows 95 OSR2, Windows 98 hDevice := CreateFile('\\.\SMARTVSD', 0, 0,

查看硬盘序列号(篇六)

改变硬盘序列号码的方法

改变硬盘序列号码的方法

硬盘的号码有时候是需要改变的,这是因为有些软件的许可证号码是和硬盘号码有关系的。

更改硬盘号的步骤:

(1)一般需要使用windows启动盘启动计算机。

(2)使用VOL命令,查看欲修改的硬盘序列号码,并用笔记录。

例如:

该硬盘号码为0B3214E7

(2)启动Debug

(3)使用L命令将硬盘中存放硬盘序列号放入开始地址为100的内存中。

命令格式 L 内存开始地址 驱动器代码 开始扇区 扇区数

其中:内存开始地址 一般为100

驱动器代码 A盘------0

B盘------1

C盘------2

D盘------3

开始扇区 磁盘序列号放在0扇区

扇区数 取一个扇区就可以

例: L 100 2 0 1 表示将C盘的第0扇区放入开始地址为100的内存中

(4)使用D命令观察内存内容

命令格式:D [地址]

例: D 100 表示将内存地址为100的内容显示到屏幕上

(5) 在屏幕上找硬盘序列号,將记录的硬盘号码与显示的内容相比较,找硬盘号的地址

例如,硬盘号码是0B3214E7, 经过比较,可知硬盘序列号的地址是143,144,145和146 注意:各个计算机的硬盘号码所在地址不同,都需要通过比较的方法寻找

找到后,可以输入命令:D 143 以确定号码地址的正确性。

(5) 修改硬盘号码,将修改的硬盘号码写入内存。

命令格式:E 地址 内容

其中: 地址 为欲修改内存的地址

内容 为修改后的内容,在这里是硬盘号码 ,如果要将硬盘号码修改为22e75628 则输入:

E 143 28

E 144 56

E 145 e7

E 146 22

(6)使用写入命令将内存中内容写入硬盘

命令格式: W 内存开始地址 驱动器代码 开始扇区 扇区数

其中,内存开始地址、驱动器代码、开始扇区、扇区数,应该和L命令的参数一致,这一点非常重要,否则硬盘就不能使用了。

下图表示了全过程:

(7)使用Q命令退出DEBUG,启动计算机后,再用VOL命令检查硬盘序列号,可以观察到硬盘号已经变了。

许可证文件的处理

(1)许可证文件

许可证可以从互连网上向Lattice公司申请,只要把硬盘号码用互连网发往该公司,该公司将用E-mail把一个许可证文件邮过来,该文件中有很多注释语句,只有三行语句有用,将所有注释语句删除,只留三行语句,然后存盘,就形成了能用的许可证文件。 许可证文件中有用的三行语句:

FEATURE LSC_STARTER lattice 8.000 29-sep-2000 uncounted \

(2)许可证文件放在哪一个子目录中

许可证文件应该放在ispEXPERT的目录(默认目录是c:\ispTOOLS)中的ispcomp\licence子目录中,(c:\ispTOOLS\Ispcomp\licence)

注意:应该在安装该软件时,允许软件修改autoexec.bat文件,将许可证文件的默认路径写入自动批处理文件(autoexec.bat),并且尽量不要修改软件的默认路径。

(3)使用该软件的方法有两个:

一是从Lattice公司获取许可证号码,然后使用软件,该方法适用于上网的计算机 二是找到一个许可证文件,然后按照文件上的硬盘号码修改计算机的硬盘号码,该方法适合没上网的计算机,或教学上多台计算机使用该软件的情况

(4) isp EXPERT 7.0 许可证的申请方法

Lattice 公司的网址:

1 进入主页中的Design Tools

2 在Downloadable一栏中选择ispEXPERT System Starter Softwere

3 在Web Site Procedures 中选择3 request a six month license file

4 申请license.dat 文件时有两个选择:ispSynario SystemStarter Softwewe和ispEXPERT system Stater Softwewe ,请选择后者ispEXPERT system Stater Softwewe

5 填入你的硬盘号码。 700080301C8C1B0D1A5B VENDOR_STRING="ispDesignEXPERT System \ (Starter)" HOSTID=DISK_SERIAL_NUM=b3214e7 最后一行的最后的字符0b3214e7是硬盘号码。

    查看硬盘序列号 获取硬盘物理序列号由作业高手网(www.solandy.net)收集整理,转载请注明出处!原文地址http://www.solandy.net/wuli/2017/0708/311359.html

    文章评论
    Copyright © 2006 - 2017 www.solandy.net All Rights Reserved
    作业高手网 版权所有

    澳门葡京网上娱乐平台