kneze Posted April 2, 2018 Posted April 2, 2018 Hi first step i write ipconfig output to ipconfig.txt. Now i try to find all Adapters and get for each adapter: Adapter Name, Description, Media State and Mac Adress and put it to listbox. I search for "Ethernet Adapter" but they are other entrys like Wireless Adapter .. How can i get all Adapters from ipconfig.txt and information for each adapter Adapter Name, Description, Media State and Mac Adress and write to listbox ? Would appreciate any help! expandcollapse popup#include <File.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 451, 328, 856, 237) $Button1 = GUICtrlCreateButton("Button1", 8, 8, 75, 25) $List1 = GUICtrlCreateList("", 88, 8, 353, 305) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select ;Case $GUI_EVENT_CLOSE Case $msg = $GUI_EVENT_CLOSE Exitloop Case $msg = $Button1 $FilePath= "C:\temp\IPconfig.txt" $StringToSearch= "Ethernet adapter" $CaseSense=0 $Lines=_FileCountLines($FilePath) $hFile=FileOpen($FilePath,0) $Lines=_FileCountLines($FilePath) For $i=0 To Number($Lines) $Test=FileReadLine($hFile,$i) If StringInStr($Test,$StringToSearch,$CaseSense) Then $filereadAdapter = FileReadLine($hFile,$i) $filereadDescription = FileReadLine($hFile,$i+4) $filereadMediaState = FileReadLine($hFile,$i+2) $filereadMAcAdress = FileReadLine($hFile,$i+5) GUICtrlSetData($List1 , "Adapter: " & $filereadAdapter & @CRLF& "Description: "& $filereadDescription & @CRLF & "Media State: " & $filereadMediaState & @CRLF & "Mac Adress: " & $filereadMAcAdress& @CRLF) ;ExitLoop EndIf Next FileClose($hFile)
Subz Posted April 2, 2018 Posted April 2, 2018 Try something like this instead: expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> Local $aNetworkAdapterInfo = _NetworkAdapterInfo() $hForm = GUICreate("Form1", 451, 328, 856, 237) $idButton = GUICtrlCreateButton("Button1", 8, 8, 75, 25) $idListView = GUICtrlCreateListView("Name|Description|Media State|Mac Address", 88, 8, 353, 305) _GUICtrlListView_AddArray($idListView, $aNetworkAdapterInfo) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exitloop Case $idButton _GUICtrlListView_DeleteAllItems($idListView) $aNetworkAdapterInfo = _NetworkAdapterInfo() _GUICtrlListView_AddArray($idListView, $aNetworkAdapterInfo) EndSwitch WEnd Func _NetworkAdapterInfo($_sComputerName = @ComputerName) Local $aAdapter[0][4], $oAdapterConfigs Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\" & $_sComputerName & "\root\cimv2") If Not IsObj($objWMIService) Then Exit MsgBox(48, "Error", "Unable to connect to " & $_sComputerName) Local $oAdapterConfigs = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") For $oAdapterConfig in $oAdapterConfigs $oAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapter") If Not IsObj($oAdapters) Then ContinueLoop For $oAdapter In $oAdapters If $oAdapter.MacAddress = $oAdapterConfig.MacAddress Then _ArrayAdd($aAdapter, $oAdapter.NetConnectionId & "|" & $oAdapterConfig.Description & "|" & _NAMediaState($oAdapter.NetConnectionStatus) & "|" & $oAdapterConfig.MacAddress) EndIf Next Next Return $aAdapter EndFunc Func _NAMediaState($_iNAMediaState) Switch $_iNAMediaState Case 0 Return "Disconnected" Case 1 Return "Connecting" Case 2 Return "Connected" Case 3 Return "Disconnecting" Case 4 Return "Hardware not present" Case 5 Return "Hardware disabled" Case 6 Return "Hardware malfunction" Case 7 Return "Media disconnected" Case 8 Return "Authenticating" Case 9 Return "Authentication succeeded" Case 10 Return "Authentication failed" Case Else Return "Unknown State" EndSwitch EndFunc
kneze Posted April 8, 2018 Author Posted April 8, 2018 Thank you for your assistance Subz. Its great and works.
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