硬盘序列号:
这有源程序:
http://www.codeguru.com/system/DiskId32.shtml
这也有:
http://www.csdn.net/cnshare/soft/4/4806.html CPU ID:
http://www.csdn.net/cnshare/soft/7/7899.html
这有源程序:
http://www.codeguru.com/system/DiskId32.shtml
这也有:
http://www.csdn.net/cnshare/soft/4/4806.html CPU ID:
http://www.csdn.net/cnshare/soft/7/7899.html
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 LongPublic Function GetDiskNumber(strDrive As String) As Long
Dim SerialNum As Long
Dim Res As Long
Dim Temp1 As String
Dim Temp2 As String
Temp1 = String(255, Chr(0))
Temp2 = String(255, Chr(0))
Res = GetVolumeInformation(strDrive, Temp1, Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2))
GetDiskNumber = SerialNum
End Function
http://ygyuan.3322.net/
下载并安装"雁留声名录系统",然后你就可以得到第一个硬盘的序列号了!Private Declare Function GetDiskSN Lib "GetDiskSN.dll" (ByVal lpszSN As String) As DoubleDim s As String
s = String(1024, Chr(0))
GetDiskSN (s)
s = Trim(Replace(s, Chr(0), ""))
msgbox s
'you will get two different serail number for the two drives.
'It seems as if logical drives get their own serial number...
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
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim Serial As Long, VName As String, FSName As String
'Create buffers
VName = String$(255, Chr$(0))
FSName = String$(255, Chr$(0))
'get the volume information
GetVolumeInformation "C:\", VName, 255, Serial, 0, 0, FSName, 255
'Strip the extra chr$(0)'s
VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1)
FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1)
MsgBox "The Volume name of C:\ is '" + VName + "', the File system name of C:\ is '" + FSName + "' and the serial number of C:\ is '" + Trim(Str$(Serial)) + "'", vbInformation + vbOKOnly, App.Title
End Sub
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程序:Private Sub Form_Load()
Dim sDriveLetter As String
Dim RetVal As Long
Dim lpName As String
Dim nSize As Long
Dim nSerial As Long
Dim lpMaxComp As Long
Dim nFileFlags As Long
Dim lpFileName As String
lpName = Space(255)
lpFileName = Space(255)
nSize = 255 sDriveLetter = "a:\" ’这里你可以指定任何盘号 RetVal = GetVolumeInformation(sDriveLetter, lpName, _
nSize, nSerial, lpMaxComp, nFileFlags, lpFileName, nSize)
'你可以看出,不仅能得到序列号,还可以得到其他很多信息 If RetVal = 0 Then
'这里是你的错误处理代码
Exit Sub 'Quit the subroutine
Else
lblDriveSerial.Caption = CStr(nSerial)
'假定你已经建立了这个标签,将在标签上显示序列号.
End If
End Sub呵呵,大家的都一样
1
DiskSerial.DLL 版本2.11.0120 使用说明
一、动态库说明明:
二、函数说明:
三、函数调用参数及返回值说明:
四、在Microsoft Visual C++中调用:
五、在Borland C++ Builder 中调用:
六、在Borland Dephi 中调用:
七、在Visual Basic 中调用:
八、在Microsoft Visual Foxpro 中调用:
九、在Sybase Power Builder 中调用:
十、调用实例下载地址:
一、动态库说明明:
该动态库能获取硬盘的序列号、型号、修订号、磁盘缓存大小、磁头数、柱面数、每磁
道的扇区数;能获取CPU 的序列号。
二、函数说明:
1、GetDiskSerial:获取硬盘序列号、型号、修订号等物理参数。
2、GetSerialNumber:获取硬盘的物理序列号。
3、GetModelNumber:获取硬盘的型号。
4、GetRevisionNumber:获取硬盘的修订号。
5、GetBufferSize:获取硬盘的缓存大小。
6、GetDiskCylinders:获取硬盘的柱面数。
7、GetDiskHeads:获取硬盘的磁头数。
8、GetSectorsOfTrack:获取硬盘每磁道的扇区数。
9、GetCPUSerialNumber:获取CPU 的序列号。
三、函数调用参数及返回值说明:
1、GetDiskSerial:
参数:
nDrive
硬盘序号,在WINDOWS NT 4.0、WINDOWS 2000和WINDOWS XP 中,一般设
为0 即可,所对应的硬盘序号为磁盘管理中的硬盘,即磁盘管理中的磁盘0参数应设为
0,磁盘1则参数应设为1;在WINDOWS 95、WINDOWS 98和WINDOWS ME 中,
磁盘序号与硬盘所连接的IDE 接口的关,如果硬盘为第一个IDE 接口的主盘,参数设
为0,从盘设为1,为第二个IDE 接口的主盘参数为2,从盘为3。
lpDiskSerial
指向DISK_SERIAL结构的指针,该结构接收关于硬盘的物理参数。基中:
lpSerialNumber:指向接收硬盘序列号字符串缓冲区的指针。
lpModelNumber:指向接收硬盘型号字符串缓冲区的指针。
lpRevisionNumber:指向接收硬盘修订号字符串缓冲区的指针。
DiskSerial.DLL使用说明
2
lBufferSize:返回硬盘的缓存大小。
lCylinders:返回硬盘的柱面数。
lHeads:返回硬盘的磁头数。
lSectors:返回硬盘每磁道的扇区数。
lpRegNumber
指向一注册序列号字符串缓冲区的指针,如果无合法的注册序列号,请初始化为形
如“0000-0000-0000-0000”的字符串常量。
返回值:
如果函数调用成功,则返回值为非零值;如果函数调用失败,返回值为0。
2、GetSerialNumber:
参数数:
nDrive
参数说明见函数GetDiskSerial。
lpBuffer
指向接收硬盘序列号字符串缓冲区的指针。
lpRegNumber
参数说明见函数GetDiskSerial。
返回值:
如果函数调用成功,则返回值为非零值,其值为返回的硬盘序列号字符串的长度;如果
函数调用失败,返回值为0。
3、GetModelNumber:
参数:
nDrive
参数说明见函数GetDiskSerial。
lpBuffer
指向接收硬盘型号字符串缓冲区的指针。
lpRegNumber
参数说明见函数GetDiskSerial。
返回值:
如果函数调用成功,则返回值为非零值,其值为返回的硬盘型号字符串的长度;如果函
数调用失败,返回值为0。
4、GetRevisionNumber:
参数:
nDrive
参数说明见函数GetDiskSerial。
lpBuffer
指向接收硬盘修订号字符串缓冲区的指针。
lpRegNumber
参数说明见函数GetDiskSerial。
返回值:
如果函数调用成功,则返回值为非零值,其值为返回的硬盘修订号字符串的长度;如果
DiskSerial.DLL使用说明
3
函数调用失败,返回值为0。
5、GetBufferSize
参数:
nDrive
参数说明见函数GetDiskSerial。
lpRegNumber
参数说明见函数GetDiskSerial。
返回值:
如果函数调用成功,则返回值为非零值,其值为硬盘缓存的大小;如果函数调用失败,
返回值为0。
6、GetDiskCylinders
参数:
nDrive
参数说明见函数GetDiskSerial。
lpRegNumber
参数说明见函数GetDiskSerial。
返回值:
如果函数调用成功,则返回值为非零值,其值为硬盘的柱面数;如果函数调用失败,返
回值为0。
7、GetDiskHeads
参数:
nDrive
参数说明见函数GetDiskSerial。
lpRegNumber
参数说明见函数GetDiskSerial。
返回值:
如果函数调用成功,则返回值为非零值,其值为硬盘的磁头数;如果函数调用失败,返
回值为0。
8、GetSectorsOfTrack
参数:
nDrive
参数说明见函数GetDiskSerial。
lpRegNumber
参数说明见函数GetDiskSerial。
返回值:
如果函数调用成功,则返回值为非零值,其值为硬盘的每磁道的扇区数;如果函数调用
失败,返回值为0。
9、GetCPUSerialNumber
参数:
DiskSerial.DLL使用说明
4
lpCpuSerial
指向接收CPU 序列号字符串缓冲区的指针。
lpRegNumber
参数说明见函数GetDiskSerial。
返回值:
如果函数调用成功,则返回值为非零值,其值为返回的CPU 序列号字符串的长度;如
果函数调用失败,返回值为0。
四、在Microsoft Visual C++中的调用:
1、包含头文件:
#include “DiskSerial.h”
2、输入LIB 库文件:
进入菜单Project settings…|Link,在Object/library modules编辑框中输入:
DiskSerial.Lib
3、调用:
TCHAR lpBuffer[MAX_PATH], szBuffer[MAX_PATH];
DISK_SERIAL ds;
if(GetDiskSerial(0, &ds, “0000-0000-0000-0000”))
{
sprintf(szBuffer,
“Serial Number:%s,\nModel Number:%s,\nRevision Number:%s,\nBuffer
Size:%ld,\nHeads:%ld,\nCylinders:%ld,\nSectors:%ld.”,
ds.lpSerialNumber, ds.lpModelNumber, ds.lpRevisionNumber,
ds.lBufferSize, ds.lHeads, ds.lCylinders, ds.lSectors);
MessageBox(NULL, szBuffer, NULL, MB_OK);
}
if(GetCPUSerialNumber(lpBuffer, “0000-0000-0000-0000”) > 0)
MessageBox(NULL, lpBuffer, “CPU Serial Number”, MB_OK);
五、在Borland C++ Builder 中的调用:
1、包含头文件:
#include “DiskSerial.h”
2、输入LIB 库文件:
进入菜单Project |Add to project…,选择文件:DiskSerial.Lib
3、调用:
TCHAR lpBuffer[MAX_PATH], szBuffer[MAX_PATH];
DISK_SERIAL ds;
if(GetDiskSerial(0, &ds, “0000-0000-0000-0000”))
{
ShowMessage(ds.lpSerialNumber);
ShowMessage(ds.lpModelNumber);
ShowMessage(ds.lpRevisionNumber);
ShowMessage(IntToStr(ds.lBufferSize));
ShowMessage(IntToStr(ds.lHeads));
DiskSerial.DLL使用说明
5
ShowMessage(IntToStr(ds.lCylinders));
ShowMessage(IntToStr(ds.lSectors));
}
if(GetCPUSerialNumber(lpBuffer, “0000-0000-0000-0000”) > 0)
ShowMessage(lpBuffer);
六、在Borland Dephi 中的调用:
1、将DiskSerial.pas 加入工程中:
进入菜单Projrct|Add to project…,选择文件:DiskSerial.pas
2、在程序中uses部分加入DiskSerial
uses
…, DiskSerial
3、程序调用:
lpBuffer:array[0..255] of char;
ds:DISK_SERIAL;
if(GetDiskSerial(0, ds, ‘0000-0000-0000-0000’) then
begin
ShowMessage(lpDiskSerial.lpSerialNumber);
ShowMessage(lpDiskSerial.lpModelNumber);
ShowMessage(lpDiskSerial.lpRevisionNumber);
ShowMessage(IntToStr (lpDiskSerial.lBufferSize));
ShowMessage(IntToStr (lpDiskSerial.lHeads));
ShowMessage(IntToStr (lpDiskSerial.lCylinders));
ShowMessage(IntToStr (lpDiskSerial.lSectors));
end;
if(GetCPUSerialNumber(lpBuffer, ‘0000-0000-0000-0000’) > 0) then
ShowMessage(lpBuffer);
七、在Microsoft Visual Basic 中的调用:
1、将DiskSerial.bas文件加入工程中:
进入菜单Project|Add Module|Existing,选择DiskSerial.bas文件
2、调用:
Dim ds As DISK_SERIAL
Dim nRet As Long
Dim lpBuffer As String
lpBuffer = Space(MAX_PATH)
If (GetDiskSerial(0, ds, “0000-0000-0000-0000”)) Then
nRet = MessageBox(0, ds.lpSerialNumber, "Serial Number", MB_OK)
nRet = MessageBox(0, ds.lpModelNumber, "Model Number", MB_OK)
nRet = MessageBox(0, ds.lpRevisionNumber, "Revision Number", MB_OK)
nRet = MessageBox(0, ds.lBufferSize, "Buffer Size", MB_OK)
nRet = MessageBox(0, ds.lHeads, "Heads", MB_OK)
DiskSerial.DLL使用说明
6
nRet = MessageBox(0, ds.lCylinders, "Cylinders", MB_OK)
nRet = MessageBox(0, ds.lSectors, "Sectors", MB_OK)
End If
If (GetCPUSerialNumber(lpBuffer, “0000-0000-0000-0000”) > 0) Then
nRet = MessageBox(0, lpBuffer, "CPU Serial Number", MB_OK)
End If
八、在Microsoft Visual Foxpro 中的调用:
1、申明:
DECLARE INTEGER GetDiskSerial IN DiskSerial INTEGER nDrive ,;
STRING @lpDiskSerial, STRING lpRegNumber
DECLARE INTEGER GetCPUSerialNumber IN DiskSerial STRING @lpBuffer,;
STRING lpRegNumber
2、调用:
lpDiskSerial = space(260)
size=0
lpBuffer = space(260)
size = GetDiskSerial(thisform.txtDriveNumber.value, @lpDiskSerial , ;
“0000-0000-0000-0000”)
IF(size > 0)
thisform.txtSerialNumber.value = alltrim(SUBSTR(lpDiskSerial,1,32))
thisform.txtModelNumber.value = alltrim(SUBSTR(lpDiskSerial,33,32))
thisform.txtRevisionNumber.value = alltrim(SUBSTR(lpDiskSerial,65,32))
thisform.txtBufferSize.value = alltrim(STR(ASC(SUBSTR(lpDiskSerial,100,1)) * ;
16777216 + ASC(SUBSTR(lpDiskSerial,99, 1)) * 65536 +;
ASC(SUBSTR(lpDiskSerial,98, 1)) * 256 + ASC(SUBSTR(lpDiskSerial,97, 1))))
thisform.txtCylinders.value = alltrim(STR(ASC(SUBSTR(lpDiskSerial,104,1)) * ;
16777216 + ASC(SUBSTR(lpDiskSerial,103, 1)) * 65536 + ;
ASC(SUBSTR(lpDiskSerial,102, 1)) * 256 + ASC(SUBSTR(lpDiskSerial,101, 1))))
thisform.txtHeads.value = alltrim(STR(ASC(SUBSTR(lpDiskSerial,108,1)) * ;
16777216 + ASC(SUBSTR(lpDiskSerial,107, 1)) * 65536 +;
ASC(SUBSTR(lpDiskSerial,106, 1)) * 256 + ASC(SUBSTR(lpDiskSerial,105, 1))))
thisform.txtSectors.value = alltrim(STR(ASC(SUBSTR(lpDiskSerial,112,1)) * ;
16777216 + ASC(SUBSTR(lpDiskSerial,111, 1)) * 65536 + ;
ASC(SUBSTR(lpDiskSerial,110, 1)) * 256 + ASC(SUBSTR(lpDiskSerial,109, 1))))
ENDIF
size = GetCPUSerialNumber(lpBuffer, “0000-0000-0000-0000”)
IF (size > 0) then
thisform.txtCPUSerial.value = alltrim(lpBuffer(1, size))
ENDIF
九、在Sybase Power Builder 中调用:
DiskSerial.DLL使用说明
7
1、建立DISK_SERIAL 结构类型:
进入菜单,选择New…|Object,选择Structure,分别输入以下变量:
Type Variable Name
Char lpSerialNumber[32]
Char lpModelNumber[32]
Char lpRevisionNumber[32]
Long lBufferSize
Long lCylinders
Long lHeads
Long lSectors
存盘保存结构类型为DISK_SERIAL。
2、函数申明:
申明Local External Functions:
Function boolean GetDiskSerial(int nDrive, ref DISK_SERIAL lpDiskSerial, string
lpRegNumber) library "DiskSerial.DLL"
Function uint GetCPUSerialNumber(ref string lpBuffer, string lpRegNumber) library
"DiskSerial.DLL"
3、调用:
string lpBuffer
boolean bResult
uint uiResult
disk_serial ds
bResult = GetDiskSerial(0, ds, “0000-0000-0000-0000”)
if(bResult = TRUE) then
sle_serialnumber.Text = ds.lpSerialNumber
sle_modelnumber.text = ds.lpModelNumber
sle_revisionNumber.text = ds.lpRevisionNumber
sle_BufferSize.text = String(ds.lBufferSize)
sle_Heads.text = String(ds.lheads)
sle_Cylinders.text = String(ds.lcylinders)
sle_Sectors.text = String(ds.lsectors)
end if
uiResult = GetCPUSerialNumber(lpBuffer, “0000-0000-0000-0000”)
if(uiResult > 0) then
sle_CPUSerial.text = lpBuffer
end if
十、调用实例下载地址:
在MS Visual C++中调用实例:
MFC: http://vip.6to23.com/songdai/download/DiskSerial/MFC.zip
API: http://vip.6to23.com/songdai/download/DiskSerial/API.zip
在Borland C++ Builder 中调用实例:
DiskSerial.DLL使用说明
8
http://vip.6to23.com/songdai/download/DiskSerial/BCB.zip
在Borland Dephi 中调用实例:
http://vip.6to23.com/songdai/download/DiskSerial/Dephi.zip
在MS Visual Basic 中调用实例:
http://vip.6to23.com/songdai/download/DiskSerial/VB.zip
在MS Visual Foxpro 中调用实例:
http://vip.6to23.com/songdai/download/DiskSerial/VFP.zip
在Sybase Power Builder 中调用实例:
http://vip.6to23.com/songdai/download/DiskSerial/PB.zip
我靠,wonderful,不用花钱买书了
'''''''''''''
'Call Module : CSystem
Option ExplicitPrivate Type SYSTEM_INFO
wProcessorArchitecture As Integer
wReserved As Integer
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
wProcessorLevel As Integer
wProcessorRevision As Integer
End TypePrivate Declare Sub GetSystemInfo Lib "KERNEL32" (lpSystemInfo As SYSTEM_INFO)Private iWinMajor As Integer
Private iWinMinor As Integer
Private sMode As String
Private sys As SYSTEM_INFOPrivate Sub Class_Initialize()
Dim dw As Long, c As Integer
dw = GetVersion()
iWinMajor = dw And &HFF&
iWinMinor = (dw And &HFF00&) / &H100&
sMode = IIf(dw And &H80000000, "Windows 95", "Windows NT")
GetSystemInfo sys
End SubProperty Get FreePhysicalMemory() As Long
Dim mem As MEMORYSTATUS
mem.dwLength = Len(mem)
GlobalMemoryStatus mem
FreePhysicalMemory = mem.dwAvailPhys \ 1024
End PropertyProperty Get TotalPhysicalMemory() As Long
Dim mem As MEMORYSTATUS
mem.dwLength = Len(mem)
GlobalMemoryStatus mem
TotalPhysicalMemory = mem.dwTotalPhys \ 1024
End PropertyProperty Get FreeVirtualMemory() As Long
Dim mem As MEMORYSTATUS
mem.dwLength = Len(mem)
GlobalMemoryStatus mem
FreeVirtualMemory = mem.dwAvailVirtual \ 1024
End PropertyProperty Get TotalVirtualMemory() As Long
Dim mem As MEMORYSTATUS
mem.dwLength = Len(mem)
GlobalMemoryStatus mem
TotalVirtualMemory = mem.dwTotalVirtual \ 1024
End PropertyProperty Get FreePageFile() As Long
Dim mem As MEMORYSTATUS
mem.dwLength = Len(mem)
GlobalMemoryStatus mem
FreePageFile = mem.dwAvailPageFile \ 1024
End PropertyProperty Get TotalPageFile() As Long
Dim mem As MEMORYSTATUS
mem.dwLength = Len(mem)
GlobalMemoryStatus mem
TotalPageFile = mem.dwTotalPageFile \ 1024
End PropertyProperty Get MemoryLoad() As Long
Dim mem As MEMORYSTATUS
mem.dwLength = Len(mem)
GlobalMemoryStatus mem
MemoryLoad = mem.dwMemoryLoad
End PropertyProperty Get WinMajor() As Integer
WinMajor = iWinMajor
End PropertyProperty Get WinMinor() As Integer
WinMinor = iWinMinor
End PropertyProperty Get WinVersion() As Single
WinVersion = iWinMajor + (iWinMinor / 100)
End PropertyProperty Get Processor() As String
If sMode = "Windows 95" Then
Processor = "Intel "
Select Case sys.dwProcessorType
Case 386
Processor = Processor & "386"
Case 486
Processor = Processor & "486"
Case 586
Processor = Processor & "586"
End Select
Else
Select Case sys.wProcessorArchitecture
Case PROCESSOR_ARCHITECTURE_INTEL
Processor = "Intel "
Select Case sys.wProcessorLevel
Case 3, 4
Processor = Processor & sys.wProcessorLevel & "86"
Case 5
Processor = Processor & "Pentium"
Case Else
Processor = Processor & "Level " & sys.wProcessorLevel
End Select
Case PROCESSOR_ARCHITECTURE_MIPS
Processor = "MIPS R" & sys.wProcessorLevel & "000"
Case PROCESSOR_ARCHITECTURE_ALPHA
Processor = "Alpha " & sys.wProcessorLevel
Case PROCESSOR_ARCHITECTURE_PPC
Processor = "Power PC " & IIf(sys.wProcessorLevel > 9, "6", "60") & _
sys.wProcessorLevel
Case PROCESSOR_ARCHITECTURE_UNKNOWN
Processor = "Unknown"
Case Else
Processor = "Other " & sys.wProcessorArchitecture & " " & sys.wProcessorLevel
End Select
End If
End PropertyProperty Get ProcessorCount() As String
ProcessorCount = sys.dwNumberOfProcessors
End PropertyProperty Get Mode() As String
Mode = sMode
End PropertyProperty Get WindowsDir() As String
Dim s As String, c As Long
s = String$(cMaxPath, 0)
c = GetWindowsDirectory(s, cMaxPath)
WindowsDir = Left(s, c)
End PropertyProperty Get SystemDir() As String
Dim s As String, c As Long
s = String$(cMaxPath, 0)
c = GetSystemDirectory(s, cMaxPath)
SystemDir = Left(s, c)
End PropertyProperty Get User() As String
Dim s As String, c As Long
c = 80: s = String$(c + 1, 0)
' Includes null in returned length, unlike all other API functions
If GetUserName(s, c) Then User = Left$(s, c - 1)
End PropertyProperty Get Machine() As String
Dim s As String, c As Long
c = 16: s = String$(16, 0)
If GetComputerName(s, c) Then Machine = Left$(s, c)
End Property