Allow2010 Posted May 21, 2018 Share Posted May 21, 2018 Hi, I would like to get all ip adresses if all my network adapters, so I tried something like this: $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems $strIPAddress = $objItem.IPAddress(0) ConsoleWrite("IPAddress0: " & $strIPAddress & @CRLF) $strIPAddress = $objItem.IPAddress(1) ConsoleWrite("IPAddress1: " & $strIPAddress & @CRLF) $strIPAddress = $objItem.IPAddress(2) ConsoleWrite("IPAddress2: " & $strIPAddress & @CRLF) $strIPAddress = $objItem.IPAddress(3) ConsoleWrite("IPAddress3: " & $strIPAddress & @CRLF) Next EndIf it seems that not all networ adapters provide information for more than one ip adress so this keeps failing with the following output: Quote IPAddress0: IPAddress1: IPAddress2: IPAddress3: IPAddress0: 192.168.253.1 IPAddress1: fe80::ddde:cfe6:a2d2:155c "C:\Users\Administrator\Desktop\test.au3" (18) : ==> The requested action with this object has failed.: $strIPAddress = $objItem.IPAddress(2) $strIPAddress = $objItem^ ERROR how can i prevent the error so that the script contines? I never worked with WMI Objects before... Thanks! Link to comment Share on other sites More sharing options...
water Posted May 21, 2018 Share Posted May 21, 2018 Add a COM error handler to your script. Teh help file describes this in ObjEvent. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
jguinch Posted May 21, 2018 Share Posted May 21, 2018 The problem is that you use a non existing array index : $objItem.IPAddress(2) Check the size of the element and use an loop to enumerate IP adresses : $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If Not IsObj($colItems) Then Exit For $objItem In $colItems ConsoleWrite("[" & $objItem.Description & "]" & @CRLF) $aIPAddress = $objItem.IPAddress If UBound($aIPAddress) Then For $i = 0 To UBound($aIPAddress) - 1 ConsoleWrite("- " & $aIPAddress[$i] & @CRLF) Next Else ConsoleWrite("! No IP adress" & @CRLF) EndIf Next Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Allow2010 Posted May 21, 2018 Author Share Posted May 21, 2018 thanks, both answers will help ! Link to comment Share on other sites More sharing options...
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