Sign in to follow this  
Followers 0
botanic

Problem "reparing" internet

6 posts in this topic

The problem is that I somehow need to set $NetWorkName to the name of the connection that the adapter relates to so that it will repair whatever connection that you invoke the switched IP on...

#RequireAdmin
Global $WinShell= ObjCreate("shell.application"), $ControlPanel = 3, _
$NetConTitle    = 'Network Connections', _    ; Name of the window you see whenever you open "Network Connections" from the Control Panel
$NetWorkName    = 'Wireless Network Connection'; Name of the connection you'd wish to invoke a function on

Func RepairConnection($NetWorkName)
    For $ControlPanelItem in $WinShell.NameSpace($ControlPanel).Items
        If $ControlPanelItem.Name = $NetConTitle Then
            For $NetConnection In $ControlPanelItem.GetFolder.Items
                If $NetConnection.Name = $NetWorkName Then ExitLoop(2)
            Next
        EndIf
    Next
    $NetConnection.InvokeVerb('Re&pair')                                    ;Invoke the function
    If WinWaitActive('Repair ' & $NetworkName, 'finished repairing', 45) Then _;As soon as the repairment took place or 45 seconds have passed
        Send('{TAB}{ENTER}')                                                ;Close the window by sending {ALT}{ENTER}
EndFunc



DirCreate(@ProgramFilesDir & "\Easy Network Switcher")
$networkini = @ProgramFilesDir & "\Easy Network Switcher\Adaptor List.ini"

global $1, $b12, $b11, $var, $disc, $servicename,$tmm , $tmp,$cur = "", $ck, $GUID, $TMP, $name,  $current, $del

if FileExists($networkini) then
    $del = IniReadSectionNames($networkini)
    For $1 = 1 to $del[0]
    IniDelete($networkini, $del[$1])
    Next

EndIf

   
For $i= 1 to 99999
    $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards", $i)
    If @error <> 0 then ExitLoop
    $disc = StringReplace(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $var , "Description"),"/","")
    $servicename = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $var , "ServiceName")
    IniWrite($networkini, $disc, "GUID", $servicename)
    IniWrite($networkini, $disc, "NID", $var)
Next

global $hCombo

#include <GUIConstants.au3>
#include <GuiComboBoxEx.au3>

Func _placevalue($name, $guid)
Local   $msg = -1
local $hCombo2 , $b111
$hGUI2 = GUICreate($cur, 400, 130)
$b111 = GUICtrlCreateButton("Apply Setting Profile",5,103)
$b22 = GUICtrlCreateButton("Remove",124, 103)
$b12 = GUICtrlCreateButton("Return",324, 103)
$hCombo2 = _GUICtrlComboBoxEx_Create ($hGUI2, "", 2, 2, 394, 100, BitOR($CBS_SIMPLE, $WS_VSCROLL, $WS_BORDER))
GUISetState()

$ini = IniReadSectionNames(@ProgramFilesDir & "\Easy Network Switcher\Profiles.ini")
if $ini <> @error Then
For $1 = 1 to $ini[0]
_GUICtrlComboBoxex_AddString($hCombo2, $ini[$1])
Next
Else
    MsgBox(48, "Error", "There are no saved profiles to restore")
                            GUIDelete($hGUI2)
                        _start()
EndIf

while 1
    $msg = GUIGetMsg()
    $current = _GUICtrlComboBoxEx_GetCurSel($hCombo2)
    $tmm = IniReadSectionNames(@ProgramFilesDir & "\Easy Network Switcher\" & $name)
    if $tmm <> @error Then $current = $tmm[$current+1]
            Select
                    Case $msg = $GUI_EVENT_CLOSE
                        GUIDelete($hGUI2)
                        _start()
                    Case $msg = $b22
                        IniDelete(@ProgramFilesDir & "\Easy Network Switcher\" & $name, $current)
                    GUIDelete($hGUI2)
                        _placevalue($name, $guid)
                    Case $msg = $b111
                        $NetWorkName = $name
                        $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "EnableDHCP", "1");1
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "EnableDHCP", "REG_DWORD", $var)
                        $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "IPAddress", "0.0.0.0");1
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "IPAddress", "REG_MULTI_SZ", $var)
                        $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "SubnetMask", "0.0.0.0");1
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "SubnetMask", "REG_MULTI_SZ", $var)
                        $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "DefaultGateway", "");1
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGateway", "REG_MULTI_SZ", $var)
                        $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "DefaultGatewayMetric", "")
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGatewayMetric", "REG_MULTI_SZ", $var)
                        $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "NameServer", "")   
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "NameServer", "REG_SZ",$var)
                        RepairConnection($NetWorkName) 
                        MsgBox(48, "Apply", "Settings were applied")
                        GUIDelete($hGUI2)
                        _start()
Case $msg = $b12
                        GUIDelete($hGUI2)
                        _start()
        EndSelect
WEnd
EndFunc
_start()
Func _start()
    Local $msg
$hGUI = GUICreate("Network Easy Switcher", 400, 130)
$b1 = GUICtrlCreateButton("Save Current Settings",5,103)
$b2 = GUICtrlCreateButton("Apply Custom Settings",124, 103)
$b3 = GUICtrlCreateButton("Reset Default Settings",245, 103)
$hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100, BitOR($CBS_SIMPLE, $WS_VSCROLL, $WS_BORDER))
GUISetState()
   
$ini = IniReadSectionNames($networkini)
For $1 = 1 to $ini[0]
_GUICtrlComboBoxex_AddString($hCombo, $ini[$1])
Next

While 1
    $msg = GUIGetMsg()

    if $msg = $b1 or $msg = $b2 or $msg = $b3 or $msg = $gui_event_Close then
        $var = _GUICtrlComboBoxEx_GetCurSel($hCombo)
           
        If $var <> -1 Then
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        Exit
                    Case $msg = $b1
                                                $cur = $ini[$var+1]
                        $name = $cur
                        $GUID = IniRead($networkini, $name, "GUID", "")
                            $name = "Profiles.ini"
                        $current = InputBox("Name Settings", "Please type a name for these settings.", "")
                    if $current <> "" and $current <> "Default" Then
                        $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "EnableDHCP")
                        IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "EnableDHCP", $var);1
                        $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "IPAddress")
                        IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "IPAddress", $var);1
                        $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "SubnetMask")
                        IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "SubnetMask", $var);1
                        $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGateway")
                        IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "DefaultGateway", $var);1
                        $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGatewayMetric")
                        IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "DefaultGatewayMetric", $var)
                        $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "NameServer")
                        IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "NameServer", $var)
                    ElseIf $current = "" then
                        MsgBox(48, "Error", "You must type a name for these settings.")
                    Else
                        MsgBox(48, "Error", "The name 'Default' is reserved by the system.")                   
                    EndIf
                   
                Case $msg = $b2
                        $cur = $ini[$var+1]
                        $name = $cur
                        $GUID = IniRead($networkini, $name, "GUID", "")
                        GUIDelete()
                        GUICtrlSetState($hCombo, @SW_hide)
                        $name = "Profiles.ini"
                        _placevalue($name , $GUID)
                        ExitLoop
                    Case $msg = $b3
                                                $cur = $ini[$var+1]
                        $name = $cur
                       
                        $GUID = IniRead($networkini, $name, "GUID", "")
                        $name = "Profiles.ini"
                        $NetWorkName = $name
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "EnableDHCP", "REG_DWORD", "1")
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "IPAddress", "REG_MULTI_SZ", "0.0.0.0")
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "SubnetMask", "REG_MULTI_SZ", "0.0.0.0")
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGateway", "REG_MULTI_SZ", "")
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGatewayMetric", "REG_MULTI_SZ", "")
                        $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "NameServer", "REG_SZ","")
                        RepairConnection($NetWorkName) 
                        MsgBox(48, "Default", "Windows Default restored.")
                EndSelect
            Else
            if $msg = $GUI_EVENT_CLOSE then Exit
            MsgBox(48, "OPPS!!!", "Please select a Network Card")
            $msg = 0
        EndIf
    EndIf
   
Wend

EndFunc

Share this post


Link to post
Share on other sites



Too much code to take the time to pick your issue out of all the extraneous stuff. But this will list interfaces and their IP address(es) so you can pick out the one you need:

#include <Array.au3>

Global Const $wbemFlagReturnImmediately = 0x10
Global Const $wbemFlagForwardOnly = 0x20
Global $wbemFlags = BitAND($wbemFlagReturnImmediately, $wbemFlagForwardOnly)

Global $strComputer = @ComputerName
Global $IPAddresses

Global $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
Global $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", $wbemFlags)
If $colItems.count Then
    Global $avNICs[$colItems.count + 1][4] = [[$colItems.count, "", "", ""]]
    $n = 1
    For $objItem In $colItems
        With $objItem
            $avNICs[$n][0] = .Caption
            $avNICs[$n][1] = .SettingID
            If .DHCPEnabled Then
                $avNICs[$n][2] = "True"
            Else
                $avNICs[$n][2] = "False"
            EndIf
            $IPAddresses = .IPAddress
            If IsArray($IPAddresses) Then $avNICs[$n][3] = _ArrayToString($IPAddresses, ",")
        EndWith
        $n += 1
    Next
    _ArrayDisplay($avNICs, "NIC Info: Caption | ID | DHCP | IP Address(es)")
EndIf

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

nice script just thats not what i need ;/ I basically need to know the name of the network ie "Local Area Connection" or "Wireless Internet Connection" from the adapter name or the NID

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

nice script just thats not what i need ;/ I basically need to know the name of the network ie "Local Area Connection" or "Wireless Internet Connection" from the adapter name or the NID

I don't know which name you mean. The "caption" filed listed at [$n][0] matches the "Description" listed when I do IPCONFIG /ALL from a command line (minus the index number in square brackets).

This description matches that in the registry at:

$sRegVal = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $n + 1 & "\Description"

The registry settings for this NIC are at:

$sRegVal = "HKLM\SYSTEM\ControlSet001\Services\" & $avArray[$n][1] & "\Parameters\Tcpip"
because the SettingID is how it's identified in the registry.

What exactly are you looking for?

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

When you are in Network Connections the name like Local Area Connection the appears. I need the name to repair the connection.

NOTE: The name is NOT in IPconfig/all

Share this post


Link to post
Share on other sites

When you are in Network Connections the name like Local Area Connection the appears. I need the name to repair the connection.

NOTE: The name is NOT in IPconfig/all

Ah. That would be at:
$sRegVal = "HKLM\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\" & $avArray[$n][1] & "\Connection\Name"

But there may be a more direct way to pull that from WMI. Just cruise Scriptomatic and look at the Win32_Net* classes.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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
Sign in to follow this  
Followers 0