Jump to content
kneze

filter txt file with information from ipconfig

Recommended Posts

kneze

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!

#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)

 

 

Share this post


Link to post
Share on other sites
Subz

Try something like this instead:

#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

 

Share this post


Link to post
Share on other sites
kneze

Thank you for your assistance Subz.

Its great and works.

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      can we  create a list box with  Columns?
      welcome everybody
      Dears I have a question if you let me
      can we  create a list box with  Columns?
      i know we can create a list view with Columns
      but my question is about the list box
      I'm waiting your responses
      Thank you in advance
    • hcI
      By hcI
      Hello
      Today I'm working on listbox but there might be something that I'm missing...
      I made a little script that allow the user to swap 2 items for the listbox. So the user select for example the 3rd item, press the button "Up" and it switch with the 2nd one, same with the "Down" button that switch with the 4th one.
      But when I select the 3rd item and switch it the item become unselected and I would like to select it again after the manipulation :
      As you can see in the comment of the script, _GUICtrlListBox_SetSel don't highlight/select them once the swap process is done..
      What am I missing ?
    • Daka
      By Daka
      I know there are listbox and listview, but now I have?
      here is the video of infowindow 
      I tried to read mouse selection like for listbox:
      $listWindow = "[CLASS:TFormResearchGR]" $topicsList = "[CLASS:TMWrapper; INSTANCE:255]" WinWait($listWindow, "", 60) $hdlWindow = WinGetHandle($listWindow) $hdlList = ControlGetHandle($hdlWindow, "", $topicsList) _GUICtrlListBox_ClickItem($hdlList, 0, "left") $countOfList = _GUICtrlListBox_GetCount($hdlList) ConsoleWrite("Count of list: " & $countOfList & @LF) count of list is not working.
      I realiezed that there are difference between listbox and listview, but this is something different.
      and till now I never saw that you can go inside with infotool and also get instances.
       
      so Im confused how to get the list number and the names of selection?
    • Guy_
      By Guy_
      This is not a working example -- I'm asking about the principle...
      Here we have the often seen code to detect a double-click on an item in one ListBox (ID in $idListBox is of course created by other code).
      To catch that ListBox item, I have only added $sBookmark to it. This could be a pick list application.
      $idListBox = 0x004A0FB0 GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox, _ $sBookmark If Not IsHWnd($idListBox) Then $hWndListBox = GUICtrlGetHandle($idListBox) $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $idListBox, $hWndListBox $sBookmark = _GUICtrlListBox_GetText( $hWndFrom, _GUICtrlListBox_GetCurSel($hWndFrom) ) Switch $iCode Case $LBN_DBLCLK ConsoleWrite("you double-clicked " & $sBookmark & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc  
      Now, my question is: can one modify the _WM_COMMAND function to allow for a dynamic number of ListBoxes? (meaning, user-defined -- the amount of ListBoxes/pick lists can change at any time).
      Let's assume I dynamically obtained an array with ListBox ID's for (in this case) 5 pick lists:

      One part of the solution seems to work with the For... Next loop I added below, but I'm wondering if that is the ultimate? (knowing this Func has to be as fast as possible)
      The part where I can't find anything that works for a dynamic amount of ListBox ID's is in the Case check...
      I tried _ArrayToTxt($aIdListBox, ", ", 1), messed with Eval(), and trying Case $aIdListBox[start] To $aIdListBox[end]
       
      Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox, _ $sBookmark For $i = 1 To UBound($aIdListBox) - 1 ; is this solution fast enough? (it seems to work well) If Not IsHWnd($aIdListBox[$i]) Then $hWndListBox = GUICtrlGetHandle($aIdListBox[$i]) ExitLoop ; cause there can only be one hit(?) EndIf Next $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case [WHAT TO PUT HERE if nr of ListBoxes is dynamic?], $hWndListBox ; <= MAIN question $sBookmark = _GUICtrlListBox_GetText( $hWndFrom, _GUICtrlListBox_GetCurSel($hWndFrom) ) Switch $iCode Case $LBN_DBLCLK ConsoleWrite("you double-clicked " & $sBookmark & @CRLF) EndSwitch Return $GUI_RUNDEFMSG EndFunc - - -
      As a workaround, I can probably add the maximum number of allowed ListBoxes to the Case check, seperated by commas, but only display the number of ListBoxes needed. But I'm hoping it can be made truly dynamical...?
      Thank You : )
       
    • Codartizan
      By Codartizan
      Hi Guys
      I got a problem, hope someone can help me, many thanks.
      I'm trying to read items from a listbox1($ListChoCom) to an array, and load this array to another listbox2($ListSuitCmd) which is on the different  tab. But, now, I cannot select items on the listbox2. I only can select from listbox1. Here is the code and the screenshots.
      Func btnNext2() Dim $SelCmdArray[10] For $i = 0 To _GUICtrlListBox_GetCount($ListChoCom) - 1 $SelCmdArray[$i] = _GUICtrlListBox_GetText($ListChoCom, $i) ReDim $SelCmdArray[UBound($SelCmdArray) + 1] GUICtrlSetData($ListSuitCmd, $SelCmdArray[$i]) Next _GUICtrlTab_ClickTab($Tab1, 2) EndFunc Screenshot 1: I can select item from this listbox1.

      screenshot2: I cannot select item from listbox2, The item that been highlight is what I select from listbox1.

      Thank you very much indeed.
×