BlackHoleSun Posted September 1, 2011 Posted September 1, 2011 I'm writing a program that will list the IP addresses for the active network adapters on a computer. If there are none active (wired and wireless) I would like it to reflect this, but it is going into the loop as if "If IsObj($colItems)" is true. Below is the query I'm running. expandcollapse popup#include <Array.au3> #include <Constants.au3> Global $bMACID Dim $aStatus[2] Dim $a = 0 $bMACID = False _GetNetworkInfo() Func _GetNetworkInfo() Local $wbemFlagForwardOnly = 0x20 Local $wbemFlagReturnImmediately = 0x10 Local $colItems, $objWMIService, $objItem Dim $NetworkInfoEx[3][13], $aNetInfo[30][3], $i = 1, $b = 0 $a = 0 $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) ; If IsObj($colItems) Then For $objItem In $colItems ReDim $NetworkInfoEx[UBound($NetworkInfoEx) + 1][13] Local $ipAdd = $objItem.IPAddress $NetworkInfoEx[$i][0] = $objItem.Caption $NetworkInfoEx[$i][1] = $objItem.description $NetworkInfoEx[$i][2] = $ipAdd[0] $NetworkInfoEx[$i][3] = $objItem.IPSubnet $NetworkInfoEx[$i][4] = $objItem.DefaultIPGateway $NetworkInfoEx[$i][5] = $objItem.DHCPEnabled $NetworkInfoEx[$i][6] = $objItem.DHCPServer $NetworkInfoEx[$i][7] = $objItem.DNSDomain $NetworkInfoEx[$i][8] = $objItem.DNSHostName $NetworkInfoEx[$i][9] = $objItem.DNSServerSearchOrder $NetworkInfoEx[$i][10] = $objItem.MACAddress $NetworkInfoEx[$i][11] = $objItem.WINSPrimaryServer $NetworkInfoEx[$i][12] = $objItem.WINSSecondaryServer ConsoleWrite($NetworkInfoEx[$i][1] & @CRLF) ConsoleWrite($NetworkInfoEx[$i][2] & @CRLF) $i += 1 $a += 1 Next Do $b += 1 $aNetInfo[$b][0] = $NetworkInfoEx[$b][1] $aNetInfo[$b][1] = $NetworkInfoEx[$b][10] $aNetInfo[$b][2] = $NetworkInfoEx[$b][2] MsgBox(0, $NetworkInfoEx[$b][1], $NetworkInfoEx[$b][1] & @CRLF & _ "MAC ID: " & $NetworkInfoEx[$b][10] & @CRLF & _ "IP Address: " & $NetworkInfoEx[$b][2]) Until $b = $a $NetworkInfoEx[0][0] = UBound($NetworkInfoEx) - 1 If $NetworkInfoEx[0][0] < 1 Then SetError(1, 1, 0) EndIf Else SetError(1, 2, 0) $aNetInfo[0][0] = "" $aNetInfo[0][1] = "" $aNetInfo[0][2] = "" EndIf Return $aNetInfo ;Return $NetworkInfoEx EndFunc
UEZ Posted September 1, 2011 Posted September 1, 2011 (edited) What do you mean with "...I would like it to reflect this..."? Do you want to display also non active network interfaces? Br,UEZ Edited September 1, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
BlackHoleSun Posted September 1, 2011 Author Posted September 1, 2011 What do you mean with "...I would like it to reflect this..."? Do you want to display also non active network interfaces? Br,UEZI don't want to report non-active ones, but I would like it to say "No active adapters found" or something similar.
UEZ Posted September 1, 2011 Posted September 1, 2011 Try this: expandcollapse popup#include <Array.au3> #include <Constants.au3> Global $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler") $aResult = _GetNetworkInfo() If Not @error Then _ArrayDisplay($aResult) ElseIf @error = 1 Then MsgBox(0, "Information", "No adapter found") EndIf Func _GetNetworkInfo() $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x30) ; If IsObj($colItems) Then Local $NetworkInfoEx[1][13] Local $i = 0 For $objItem In $colItems ReDim $NetworkInfoEx[$i + 1][13] $NetworkInfoEx[$i][0] = $objItem.Caption $NetworkInfoEx[$i][1] = $objItem.Description Local $ipAdd = $objItem.IPAddress $NetworkInfoEx[$i][2] = $ipAdd[0] $NetworkInfoEx[$i][3] = $objItem.IPSubnet $NetworkInfoEx[$i][4] = $objItem.DefaultIPGateway $NetworkInfoEx[$i][5] = $objItem.DHCPEnabled $NetworkInfoEx[$i][6] = $objItem.DHCPServer $NetworkInfoEx[$i][7] = $objItem.DNSDomain $NetworkInfoEx[$i][8] = $objItem.DNSHostName $NetworkInfoEx[$i][9] = $objItem.DNSServerSearchOrder $NetworkInfoEx[$i][10] = $objItem.MACAddress $NetworkInfoEx[$i][11] = $objItem.WINSPrimaryServer $NetworkInfoEx[$i][12] = $objItem.WINSSecondaryServer $i += 1 Next If Not $i Then Return SetError(1, 0, 0) Return $NetworkInfoEx Else Return SetError(2, 0, 0) EndIf Return SetError(3, 0, 0) EndFunc ;==>_GetNetworkInfo Func ObjErrorHandler() ConsoleWrite( "A COM Error has occured!" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oErrorHandler.description & @CRLF & _ "err.windescription:" & @TAB & $oErrorHandler & @CRLF & _ "err.number is: " & @TAB & Hex($oErrorHandler.number, 8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oErrorHandler.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oErrorHandler.scriptline & @CRLF & _ "err.source is: " & @TAB & $oErrorHandler.source & @CRLF & _ "err.helpfile is: " & @TAB & $oErrorHandler.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oErrorHandler.helpcontext & @CRLF _ ) EndFunc Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now