On May 19, 12:41*am, "Monitor" <nos...@xxxxxx> wrote:

> "urkec" <ur...@xxxxxx> wrote in message
>
> news:F1B9D48F-F8F7-4544-9F93-01F68A86A778@xxxxxx> "Daz" wrote:
>

> > > The code i have been working with is below... the only problem i have
> > > left to resolve is getting the correct IP address to match the
> > > MacAddress and NIC. *If you have more than one NIC (hardware or
> > > software) with this code you get the last ip address
>
> '/-----------------------------------------------------------------------
>

> > > * * * Set colItems = ObjWMI.ExecQuery("Select IPAddress, MACAddress
> > > from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
>
> '/-----------------------------------------------------------------------
>

> > > * * * *For Each objItem in colItems
> > > * * * * If Not IsNull(objItem.IPAddress) Then
> > > * * * * *For i=LBound(objItem.IPAddress) To UBound(objItem..IPAddress)
> > > * * * * * IP = objItem.IPAddress(i)
> > > * * * * *Next
> > > * * * * End If
> > > * * * *Next
>
> '/-----------------------------------------------------------------------
>

> > > * * * Set colItems = ObjWMI.ExecQuery( "SELECT * FROM
> > > Win32_NetworkAdapter WHERE NetConnectionID = 'Local Area Connection'")
>
> '/-----------------------------------------------------------------------
>
>
>
>
>

> > > * * *Cnt = 1
> > > * * * *For Each objItem in colItems
> > > * * * * If Cnt = 1 Then
> > > * * * * * C1 = C1 +1
> > > * * * * * Ts.WriteLine "Line" & C1 & "=" & TitleL & "NETWORK ADAPTER
> > > INFORMATION" & TitleR
> > > * * * * * C1 = C1 +1
> > > * * * * * Ts.WriteLine "Line" & C1 & "=" & S_3 & "Adapter Name * *" &
> > > vbTab & objItem.Name
> > > * * * * * C1 = C1 +1
> > > * * * * * Ts.WriteLine "Line" & C1 & "=" & S_3 & "Manufacturer By " &
> > > vbTab & objItem.Manufacturer
> > > * * * * * C1 = C1 +1
> > > * * * * * Ts.WriteLine "Line" & C1 & "=" & S_3 & "IP Address * * *" &
> > > vbTab & IP
> > > * * * * * C1 = C1 +1
> > > * * * * * Ts.WriteLine "Line" & C1 & "=" & S_3 & "MACAddress * * *" &
> > > vbTab & objItem.MACAddress
> > > * * * * * C1 = C1 +1
> > > * * * * * Ts.WriteLine "Line" & C1 & "="
> > > * * * * *Exit For
> > > * * * * End If
> > > * * * *Next
> > > * * * Cnt = 0
>

> > You can start from Win32_NetworkAdapter and get the matching
> > Win32_NetworkAdapterConfiguration instance:
>

> > strComputer = "."
>

> > Set objWMI = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" _
> > & strComputer & "\root\cimv2")
>

> > Set colNICs = ObjWMI.ExecQuery _
> > ("Select * From Win32_NetworkAdapter " & _
> > "Where NetConnectionID = 'Local Area Connection'")
>

> > For Each objNIC in colNICs
>

> > * *Set objNICConfig = objWMI.Get _
> > * *("Win32_NetworkAdapterConfiguration.Index=" _
> > * *& objNIC.Deviceid)
>

> > * *strIP = ""
>

> > * *For Each strIPAddr In objNICConfig.IPAddress
> > * * * strIP = strIP & strIPAddr & " "
> > * *Next
>

> > * *WScript.Echo objNIC.Name
> > * *WScript.Echo objNIC.Manufacturer
> > * *WScript.Echo strIP
> > * *WScript.Echo objNIC.MACAddress
>

> > Next
>

> > --
> > urkec
>
> Nice solution! Two questions:
> - I copied your code verbatim to a .vbs file, without making any
> * *changes, then ran it on two machines. On one it ran flawlessly,
> * *on the other it generated an error message for this line of code:
>
> * *For Each strIPAddr In objNICConfig.IPAddress
>
> * *nic.vbs(19, 4) Microsoft VBScript runtime error: Object not a collection
>
> * *As I said, the code is identical on the two machines. Do you have
> * *a suggestion why objNICConfig.IPAddress might not be a collection
> * *on one machine?
>
> - Where can I look up all this useful WMI stuff?
From experience sometimes windows will assign the default NIC "Local
Area Connection2" etc and this could be the reason for not finding
it...