关于VB读取IP地址
写了一个读取IP的程序,但是只能在XP系统管用,W7读不出来,是什么原因?哪个高手给指点下?Private Sub Form_Load()
Dim IPxianzhijishu As Integer
Dim strComputer As String
Dim objWMI As Object
Dim colIP As Object
Dim IP As Object
Dim IIP As Integer
strComputer = "."
Set objWMI = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colIP = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IP In colIP
If Not IsNull(IP.IPAddress) Then
For IIP = LBound(IP.IPAddress) To UBound(IP.IPAddress)
'MsgBox "IP 地址:" & IP.IPAddress(IIP) & Chr(10) 'MsgBox "IP 地址:" & IP.IPAddress(IIP) & Chr(10) & "网卡类型:" & IP.Description(IIP) & Chr(10) & "网卡地址:" & IP.Macaddress(IIP)
If IP.IPAddress(IIP) = "192.168.253.6" Or IP.IPAddress(IIP) = "192.168.123.13" Then
'MsgBox "keyi"
IPxianzhijishu = 1 + IPxianzhijishu
Else
IPxianzhijishu = 0
End If
Next
End If
' MsgBox "IP 地址:" & IP.IPAddress(IIP)
Next
If IPxianzhijishu = 0 Then
MsgBox "IP不符"
End
End If