Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IP Script not working.

Status
Not open for further replies.

ozmoeugene

IS-IT--Management
Joined
May 6, 2004
Messages
20
Location
US
Can someone tell me why the following script is not working?

This script is right out of the book and does not work:

SCRIPT Below:

Set myObj = GetObject("winmgmts:{impersonationLevel=impersonate}" & _
"!//localhost".ExecQuery _
("select IPAddress from Win32_NetworkingAdapterConfiguration" & _
" where IPEnabled=TRUE")

'Go through the addresses
For Each IPAddress in myObj
If IPAddress.IPAddress(0) <> "0.0.0.0" Then
LocalIP = IPAddress.IPAddress(0)
Exit For
End If
Next
MsgBox LocalIP

Thanks ahead of time.
 
Have you tried something like this ?
Set myWMI = GetObject("winmgmts:\\.\root\cimv2")
Set myobj = myWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each itm in myobj
MsgBox itm.Description & ": " & itm.IPAddress(0)
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello ozmoeugene,

WMI supports passing ip address to the moniker. Your only problem is typo, sounds crazy.

Set myObj = GetObject("winmgmts:{impersonationLevel=impersonate}" & _
"!//localhost"[COLOR=red yellow])[/color].ExecQuery _
("select IPAddress from Win32_[COLOR=red yellow]Network[/color]AdapterConfiguration" & _
" where IPEnabled=TRUE")

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top