Jump to content

Recommended Posts

Posted

Hi all,

I'm trying to automate the install of a specific networking device. All goes well, I can install the driver on both Windows 7 & 10, rescan for hardware, set the IP-settings and all, but there's one issue. In Windows 10, I can disable all connection protocols using Powershell, but Windows 7 does not offer this Powershell-Cmdlet. So I programmed a way (two years ago) to let AutoIt open the network-adapter properties and then deselect all checkboxes except for the TCP/IP-V4. I recovered this snippet somewhere in my old files and tried to reintegrate this into my latest script, but it doesn't seem to work. On Windows 10 I get a blank screen for a few seconds and that's it, on Windows 7 it makes explorer crash. 

I think it's quite safe to test this on your own system as long as you're not using IPv6 to connect to the internet and as long as you return to check all the boxes again (so you don't break your connectivity).

If  anyone has any idea, I'd be glad to hear from you!

Thanks in advance and stay safe in these Corona-ridden times 🙂

Kind regards,

Jan

 


There are three functions involved:

DisableAllProtocols($AdapterName)
This one is the main function that 'should' uncheck all the checkboxes in the adapter's Properties-window.

Func DisableAllProtocols($AdapterName)
    OpenNetConnToAdapter($AdapterName)
    ;Find the IDs of all relevant controls
    Local $Handle_Window_Properties = WinWaitActive($Adaptername & " Properties","")
    Local $Handle_Listview_Protocols = ControlGetHandle($Adaptername & " Properties","","[CLASSNN:SysListView321]")
    Local $Handle_OK_Button = ControlGetHandle($Adaptername & " Properties","","[CLASSNN:Button6]")
    Local $List_CMN_ID = ControlListView($Adaptername & " Properties","","[CLASSNN:SysListView321]","FindItem","Client for Microsoft Networks")
    Local $List_FPSMN_ID = ControlListView($Adaptername & " Properties","","[CLASSNN:SysListView321]","FindItem","File and Printer Sharing for Microsoft Networks")
    Local $List_QOS_ID = ControlListView($Adaptername & " Properties","","[CLASSNN:SysListView321]","FindItem","QoS Packet Scheduler")
    Local $List_MNAMP_ID = ControlListView($Adaptername & " Properties","","[CLASSNN:SysListView321]","FindItem","Microsoft Network Adapter Multiplexor Protocol")
    Local $List_MLLDPPD_ID = ControlListView($Adaptername & " Properties","","[CLASSNN:SysListView321]","FindItem","Microsoft LLDP Protocol Driver")
    Local $List_IPV6_ID = ControlListView($Adaptername & " Properties","","[CLASSNN:SysListView321]","FindItem","Internet Protocol Version 6 (TCP/IPv6)")
    Local $List_LLTDR_ID = ControlListView($Adaptername & " Properties","","[CLASSNN:SysListView321]","FindItem","Link-Layer Topology Discovery Responder")
    Local $List_LLTDMIOD_ID = ControlListView($Adaptername & " Properties","","[CLASSNN:SysListView321]","FindItem","Link-Layer Topology Discovery Mapper I/O Driver")
    ; Disable All Protocols Except IPV4
    SetCheckboxState($Handle_Listview_Protocols,$List_CMN_ID,3)
    SetCheckboxState($Handle_Listview_Protocols,$List_FPSMN_ID,3)
    SetCheckboxState($Handle_Listview_Protocols,$List_QOS_ID,3)
    SetCheckboxState($Handle_Listview_Protocols,$List_MNAMP_ID,3)
    SetCheckBoxState($Handle_Listview_Protocols,$List_MLLDPPD_ID,3)
    SetCheckboxState($Handle_Listview_Protocols,$List_IPV6_ID,3)
    SetCheckboxState($Handle_Listview_Protocols,$List_LLTDR_ID,3)
    SetCheckboxState($Handle_Listview_Protocols,$List_LLTDMIOD_ID,3)
    ;Click OK
    ControlClick($Handle_Window_Properties,"","Button6")
    Sleep(50)
    WinClose("Network Connections")
EndFunc

OpenNetConnToAdapter($AdapterName)
This function opens the network adapter's Properties-page

Func OpenNetConnToAdapter($AdapterName)
    ShellExecute("control.exe","ncpa.cpl",@WindowsDir,"",@SW_SHOW)
    WinWait("Network Connections","")
    WinActivate("Network Connections","")
    Local $Handle_Window_NetworkConnections = WinWaitActive("Network Connections","")
    Send("{F5}")
    Sleep(250)
    Local $AdapterNameArray = StringSplit($AdapterName,"")
    For $i = 1 To $AdapterNameArray[0] Step 1
        Send($AdapterNameArray[$i])
        Sleep(10)
    Next
    Sleep(50)
    Send("{APPSKEY}")
    Sleep(50)
    Send("{R}")
    Sleep(500)
    Return
EndFunc

SetCheckboxState($Handle,$checkbox_id,$wantedstate)
This function changes the state of a checkbox

Func SetCheckboxState($handle,$checkbox_id,$wantedstate)
    ;$handle      : SysListView32-handle
    ;$checkbox_id : The ID of the checkbox you want to control
    ;$wantedstate : The wanted status (2 for checked, 3 for unchecked)
    Local $currentstate = _GUICtrlListView_GetItemStateImage($handle,$checkbox_id)
    If $currentstate = $wantedstate Then
        Return
    Else
        _GUICtrlListView_SetItemSelected($handle,$checkbox_id,True,True)
        Send("{Space}")
        Sleep(50)
        Return
    EndIf
EndFunc

 

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
×
×
  • Create New...