http://dieseyer.de • all rights reserved • © 2011 v11.4

'*** v7.9 *** www.dieseyer.de *******************************
'
' Datei: wmi-ip-adresse.vbs
' Autor: dieseyer@gmx.de
' Auf: www.dieseyer.de
'
' Ermittelt mit WMI die IP-Adresse(n) eines PCs.
'
'************************************************************

Option Explicit ' Siehe http://dieseyer.de/dse-wsh-lernen.html#OptionExpl

Dim oArgs : Set oArgs = Wscript.Arguments

Dim i, PCName

PCName = "." ' eigener PC

For i = 0 to oArgs.Count - 1 ' hole alle Argumente
If i = 0 Then PCName = oArgs.item(i)
Next

MsgBox "==>" & wmiIPadr( PCName ) & "<==", , WScript.ScriptName ' mit Function Aufruf
' MsgBox "==>" & wmiIPadr( "MEINPC" ) & "<==", , WScript.ScriptName ' mit Function Aufruf


WScript.Quit

'*** v9.5 *** www.dieseyer.de *******************************
Function wmiIPadr( PCName )
'************************************************************
Dim objWMIService, IPConfig, Tst, i

On Error Resume Next
err.Clear
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & PCName & "\root\cimv2")
Tst = err.Number & " - " & err.Description
On Error Goto 0
If Len( Tst ) > 4 Then : wmiIPadr = "Fehler: WMI-IP " & Tst : Exit Function

Dim IPConfigSet : Set IPConfigSet = objWMIService.ExecQuery ("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

wmiIPadr = ""
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
If Len( wmiIPadr ) > 0 Then wmiIPadr = wmiIPadr & "; "
wmiIPadr = wmiIPadr & IPConfig.IPAddress(i)
Next
End If
Next
Set IPConfigSet = nothing
Set objWMIService = nothing
' wmiIPadr = "IP-Adr.: " & wmiIPadr
End Function ' wmiIPadr( PCName )

http://dieseyer.de • all rights reserved • © 2011 v11.4