前两天刚收到的一个VB邮件,此免费邮件列表的订退,请访问http://www.sqdnc.com利用API测试计算机CPU的类型和序号
在一个模块中声明以下函数:
Public Type SYSTEM_INFO
dwOemID As Long
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
dwReserved As Long
End Type
Public Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
在窗体中加入以下代码,运行程序!Dim sys As SYSTEM_INFOPrivate Sub Command1_Click()
GetSystemInfo sys
Label1.Caption = "Cpu的类型为:" & sys.dwProcessorType
End SubPrivate Sub Command2_Click()
GetSystemInfo sys
Label2.Caption = "Cpu的序号为:" & sys.dwNumberOrfProcessors
End SubPrivate Sub Command3_Click()
Dim s
s = String$(200, 0)
Dim dl
Dim sz
sz = 199
dl = GetComputerName(s, sz)
Label3.Caption = dl
End Sub
在一个模块中声明以下函数:
Public Type SYSTEM_INFO
dwOemID As Long
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
dwReserved As Long
End Type
Public Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
在窗体中加入以下代码,运行程序!Dim sys As SYSTEM_INFOPrivate Sub Command1_Click()
GetSystemInfo sys
Label1.Caption = "Cpu的类型为:" & sys.dwProcessorType
End SubPrivate Sub Command2_Click()
GetSystemInfo sys
Label2.Caption = "Cpu的序号为:" & sys.dwNumberOrfProcessors
End SubPrivate Sub Command3_Click()
Dim s
s = String$(200, 0)
Dim dl
Dim sz
sz = 199
dl = GetComputerName(s, sz)
Label3.Caption = dl
End Sub
GetSystemInfo sys
Label2.Caption = "Cpu的序号为:" & sys.dwNumberOrfProcessors ********这个很搞笑啊,这是说CPU的数目,而不是序列号!*******
End Sub
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
下 面 的 这 个 例 子 是 使 用 GetVolumeInformation获 得 磁 盘 的 序 列 号 :
Private Declare Function GetVolumeInformation Lib _
"kernel32.dll" Alias "GetVolumeInformationA" (ByVal _
lpRootPathName As String, ByVal lpVolumeNameBuffer As _
String, ByVal nVolumeNameSize As Integer, _
lpVolumeSerialNumber As Long, lpMaximumComponentLength _
As Long, lpFileSystemFlags As Long, ByVal _
lpFileSystemNameBuffer As String, ByVal _
nFileSystemNameSize As Long) As Long
Function GetSerialNumber(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))
GetSerialNumber = SerialNum
End Function
调 用 时 使 用 GetSerialNumber("C:\")就 可 以 了 。
我用上面的代码在两台不同的计算机上得出的("C:\")盘的序列号是完全相同的,这是为什么啊?盼高手指教。
用VB为软件增加注册功能
郭瑞刚 对你可能有点用 不过这个代码好象也有点问题
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32s = 0Dim len5 As Long, aa As Long
Dim cmprName As String
Dim osver As OSVERSIONINFO
'取得Computer Name
cmprName = String(255, 0)
len5 = 256
aa = GetComputerName(cmprName, len5)
cmprName = Left(cmprName, InStr(1, cmprName, Chr(0)) - 1)
Computer = cmprName '取得CPU端口号
Set CPUs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("select * from Win32_Processor")
For Each mycpu In CPUs
bbb = mycpu.ProcessorId
Next