========================================================================================= ' 目 的: 取得主机板号码。 ' 参考数据: WMI Object Browser。 '========================================================================================= Public Function MBSerialNumber() As String
Dim obj As Object Dim objs As Object Dim strAnswer As String
Set objs = GetObject("WinMgmts:").InstancesOf("Win32_BaseBoard")
' 取出所有主机板的序号。 For Each obj In objs strAnswer = strAnswer & obj.SerialNumber If strAnswer < objs.Count Then strAnswer = strAnswer & "," End If Next
MBSerialNumber = strAnswer End Function 得到CPU序列号。********函数引用方法:AA = CPUInof_ME() (其中AA应为String类型)******** 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 = 0 Private Type OSVERSIONINFO 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 TypePublic Function CPUInfo_ME() As String Dim 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 CPUInfo_ME = mycpu.ProcessorId Next End Function
' 目 的: 取得主机板号码。
' 参考数据: WMI Object Browser。
'=========================================================================================
Public Function MBSerialNumber() As String
Dim obj As Object
Dim objs As Object
Dim strAnswer As String
Set objs = GetObject("WinMgmts:").InstancesOf("Win32_BaseBoard")
' 取出所有主机板的序号。
For Each obj In objs
strAnswer = strAnswer & obj.SerialNumber
If strAnswer < objs.Count Then
strAnswer = strAnswer & ","
End If
Next
MBSerialNumber = strAnswer
End Function
得到CPU序列号。********函数引用方法:AA = CPUInof_ME() (其中AA应为String类型)********
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 = 0
Private Type OSVERSIONINFO
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 TypePublic Function CPUInfo_ME() As String
Dim 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
CPUInfo_ME = mycpu.ProcessorId
Next
End Function
帮你UP
http://www.applevb.com/sourcecode/wmi.rar不使用任何DLL,获得CPU完整信息的代码。可以获得CPU的几十项信息:
http://www.applevb.com/sourcecode/Detect%20cpu.zip