1.列举所有的CPU ID:Computer = "MyMachineName"
Set CPUs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("select * from Win32_Processor")
For Each mycpu In CPUs
Msgbox mycpu.ProcessorId
Next至于Win32_Processor类的其他属性(如,2级Cache的大小等等),请参阅MSDN文章:
http://msdn.microsoft.com/library/en-us/wmisdk/hh/wmisdk/r_32hard_4bsi.asp?frame=true2.列举所有的网卡地址和IP地址:Computer = "MyMachineName"
Set networkcards = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("Select * From Win32_NetworkAdapter Where AdapterType='Ethernet 802.3'")
For Each mycard In networkcards WQL = "winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2:Win32_NetworkAdapterConfiguration=" & mycard.DeviceID
Set NIC = GetObject(WQL)
MsgBox mycard.MACAddress
MsgBox NIC.IPAddress(0) '如果一个网卡有多个IP地址,那么就改变相应的索引值
Next关于Win32_NetworkAdapterConfiguration和Win32_NetworkAdapter两个类的具体信息,请查阅MSDN文档。
3.这个例子是用来读取SCSI设备控制器的信息Computer = "MyMachineName"
Set SCSIs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("Select * From Win32_SCSIController")
For Each mycard In SCSIs
MsgBox mycard.DeviceID
NextWin32_SCSIController类的详细信息,请查阅MSDN文章。4、列举所有的SCSI磁盘ID信息。Computer = "MyMachineName"
Set SCSIs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("Select * From Win32_DiskDrive")
For Each mycard In SCSIs
MsgBox mycard.SCSITargetId
Next
MORE INFORMATION
===================
Windows Management Instrumentation (WMI) is the Microsoft implementation of Web-Based Enterprise Management (WBEM), which is an industry initiative to develop a standard technology for accessing management information in an enterprise environment. WMI uses the Common Information Model (CIM) industry standard to represent systems, applications, networks, devices, and other managed components in an enterprise environment. Applications that use WMI require Microsoft® Windows NT®/Windows® 2000, or Windows® 95/98. For information on which operating systems are required to use a particular API element, see the Requirements section of the documentation for the function, method, or property. -缺省情况下,Windows ME/2000是支持WMI的.如果要使你的系统支持WMI,请访问这个URL:http://msdn.microsoft.com/code/sample.asp?url=/msdn-files/027/001/576/msdncompositedoc.xml&frame=trueNOTE:上面的代码在Win2000下测试通过. 有些WMI类在不同的操作系统下有不同的支持和实现,具体情况还需参照MSDN文章
Set CPUs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("select * from Win32_Processor")
For Each mycpu In CPUs
Msgbox mycpu.ProcessorId
Next至于Win32_Processor类的其他属性(如,2级Cache的大小等等),请参阅MSDN文章:
http://msdn.microsoft.com/library/en-us/wmisdk/hh/wmisdk/r_32hard_4bsi.asp?frame=true2.列举所有的网卡地址和IP地址:Computer = "MyMachineName"
Set networkcards = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("Select * From Win32_NetworkAdapter Where AdapterType='Ethernet 802.3'")
For Each mycard In networkcards WQL = "winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2:Win32_NetworkAdapterConfiguration=" & mycard.DeviceID
Set NIC = GetObject(WQL)
MsgBox mycard.MACAddress
MsgBox NIC.IPAddress(0) '如果一个网卡有多个IP地址,那么就改变相应的索引值
Next关于Win32_NetworkAdapterConfiguration和Win32_NetworkAdapter两个类的具体信息,请查阅MSDN文档。
3.这个例子是用来读取SCSI设备控制器的信息Computer = "MyMachineName"
Set SCSIs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("Select * From Win32_SCSIController")
For Each mycard In SCSIs
MsgBox mycard.DeviceID
NextWin32_SCSIController类的详细信息,请查阅MSDN文章。4、列举所有的SCSI磁盘ID信息。Computer = "MyMachineName"
Set SCSIs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecQuery("Select * From Win32_DiskDrive")
For Each mycard In SCSIs
MsgBox mycard.SCSITargetId
Next
MORE INFORMATION
===================
Windows Management Instrumentation (WMI) is the Microsoft implementation of Web-Based Enterprise Management (WBEM), which is an industry initiative to develop a standard technology for accessing management information in an enterprise environment. WMI uses the Common Information Model (CIM) industry standard to represent systems, applications, networks, devices, and other managed components in an enterprise environment. Applications that use WMI require Microsoft® Windows NT®/Windows® 2000, or Windows® 95/98. For information on which operating systems are required to use a particular API element, see the Requirements section of the documentation for the function, method, or property. -缺省情况下,Windows ME/2000是支持WMI的.如果要使你的系统支持WMI,请访问这个URL:http://msdn.microsoft.com/code/sample.asp?url=/msdn-files/027/001/576/msdncompositedoc.xml&frame=trueNOTE:上面的代码在Win2000下测试通过. 有些WMI类在不同的操作系统下有不同的支持和实现,具体情况还需参照MSDN文章
也可用以下代码取得各种系统信息,不知有没有你用的:
使用GetSystemInfo去取得 程式如下
Private 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
Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)Private Sub Form_Load()
Dim sysinfo As SYSTEM_INFO
Call GetSystemInfo(sysinfo)End Sub
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 TypePrivate 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 = 0Private Sub Command1_Click()
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)
Debug.Print "Computer Name = "; cmprName'取得OS的版本
osver.dwOSVersionInfoSize = Len(osver)
aa = GetVersionEx(osver)
Debug.Print "MajorVersion "; osver.dwMajorVersion
Debug.Print "MinorVersion "; osver.dwMinorVersionSelect Case osver.dwPlatformId
Case ER_PLATFORM_WIN32s
Debug.Print "Microsoft Win32s "
Case VER_PLATFORM_WIN32_WINDOWS
If (osver.dwMajorVersion = 4) And (osver.dwMinorVersion = 0) Then
Debug.Print "Microsoft Windows 95 "
If (Mid(osver.szCSDVersion, 2, 1) = "C") Then
Debug.Print ; "OSR2 "
End If
ElseIf (osver.dwMajorVersion = 4) And (osver.dwMinorVersion = 10) Then
If Mid(osver.szCSDVersion, 2, 1) = "A" Then
Debug.Print "Microsoft Windows 98 SE"
Else
Debug.Print "Microsoft Windows 98"
End If ElseIf (osver.dwMajorVersion = 4) And (osver.dwMinorVersion = 90) Then
Debug.Print ("Microsoft Windows Me ");
End If
Case VER_PLATFORM_WIN32_NT
If osver.dwMajorVersion <= 4 Then
Debug.Print "Microsoft Windows NT " ElseIf (osver.dwMajorVersion = 5) And (osver.dwMinorVersion) = 0 Then
Debug.Print "Microsoft Windows 2000 " ElseIf (osver.dwMajorVersion = 5) And (osver.dwMinorVersion = 1) Then
Debug.Print "Whistler "
End If
End Select
End Sub