Hello,
i know this is probably a simple question, but in my defence i never programmed anything untill last week when i got the task to use Autoit to make a programm that can change IP-configs. So far i could do everything with the wiki and the tutorial is found.
So i got this Button that is supposed to update a listView with the current configuration of the network adapters. This works fine as long as all the information is there but if for example here is no DNS or gateway configured the whole thing crashes.
Follow error message: Subscript used with non-Array variable
Thanks for any help or tips
Cheers
i know this is probably a simple question, but in my defence i never programmed anything untill last week when i got the task to use Autoit to make a programm that can change IP-configs. So far i could do everything with the wiki and the tutorial is found.
So i got this Button that is supposed to update a listView with the current configuration of the network adapters. This works fine as long as all the information is there but if for example here is no DNS or gateway configured the whole thing crashes.
Follow error message: Subscript used with non-Array variable
[ autoit ]
Func UpdateAdapters() _GUICtrlListView_DeleteAllItems($ListView) $count = 0 $objWMI = ObjGet("winmgmts:\\.\root\cimv2") $collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $colNIC = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapter WHERE Netconnectionstatus = 2") Dim $pcinfo For $object In $colNIC $pcinfo = $pcinfo & $object.name & @CRLF Next For $obj In $collection If $obj.DHCPEnabled = -1 Then $currentDHCPStatus = "TRUE" Else $currentDHCPStatus = "FALSE" EndIf $currentIP = $obj.IPAddress $currentSubnet = $obj.IPSubnet $currentGateway = $obj.DefaultIPGateway $currentDNS = $obj.DNSServerSearchOrder Next For $obj In $collection $count = $count + 1 If $obj.DHCPEnabled = -1 Then $currentDHCPStatus1 = "TRUE" Else $currentDHCPStatus1 = "FALSE" EndIf $currentIP = $obj.IPAddress $currentSubnet = $obj.IPSubnet $currentGateway = $obj.DefaultIPGateway $currentDNS = $obj.DNSServerSearchOrder $item2 = GUICtrlCreateListViewItem("Name | Subnet | Gateway | DNS | DHCP", $ListView) GUICtrlSetData($item2, $pcinfo & " | " & $currentIP[0] & " | " & $currentSubnet[0] & " | " & $currentGateway[0] & " | " & $currentDNS[0] & " | " & $currentDHCPStatus) Next EndFunc
Thanks for any help or tips
Cheers