'===============================================
'一组基于 WMI 的函数
'作者:朱亦文
'时间:2009.04.27
'===============================================
'获取主板编号
Public Function MainBoardSN() As String
Dim objs As Object, Obj As Object
Set objs = GetObject("WinMgmts:").InstancesOf("Win32_BaseBoard")
For Each Obj In objs
MainBoardSN = MainBoardSN & IIf(MainBoardSN <> "", ";", "") & Obj.SerialNumber
Next
End Function
'获取网上MAC地址
Public Function NicMAC() As String
Dim Nics As Object, oIP As Object
Set Nics = GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each oIP In Nics
If oIP.IPEnabled = True Then
NicMAC = NicMAC & IIf(NicMAC <> "", ";", "") & oIP.MacAddress
Exit For
End If
Next
End Function
'获取硬盘型号
Public Function HDModel() As String
Dim hds As Object, hd As Object
Set hds = GetObject("Winmgmts:").InstancesOf("Win32_DiskDrive")
For Each hd In hds
HDModel = HDModel & IIf(HDModel <> "", ";", "") & hd.Model
Next
End Function
'获取IP地址
Public Function IP() As String
Dim OpSysSet, OpSys, oIP
Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate}//localhost"). _
ExecQuery("Select index, IPAddress FROM Win32_NetworkAdapterConfiguration")
For Each OpSys In OpSysSet
If TypeName(OpSys.IPAddress) <> "Null" Then
For Each oIP In OpSys.IPAddress
IP = IP & IIf(IP <> "", ";", "") & oIP
Next
End If
Next
End Function