Jump to content

Easy Static IP to/from AutoIP config prgram


botanic
 Share

Recommended Posts

All bugs have been fixed. It works on vista and for wireless as well as wired computers.

This program is mostly intended for laptops for people that use static ip addresses to play games ect

V1.1

#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, $t

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
                        for $i = 0 to 100
                            $t = ""
                            $t = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet00"&$i&"\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\"&$guid&"\Connection","Name")
                            if $t <> "" Then $NetWorkName = $t
                        Next
                        MsgBox(0, $GUID, $NetWorkName)
                        $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

post-18915-1203523268_thumb.jpg

Edited by botanic
Link to comment
Share on other sites

The way that the program works if you are going to an area that you dont already have a saved tcp/ip config for just click default and it will use the windows "detect automatically" configuration. You can then click the Save Custom Settings to create a static ip for the current connection. Then just click apply custom settings to apply the static ip configuration.

You are able to change the Custom settings by just selecting a new profile.

Also the profiles are cross-compatible between all of your network adapters. So if you want to switch from wireless to wired connection and have a static ip just click the wired device and apply the profile that you saved from the wireless device.

I hope that answered your question because I dont know what you are asking exactly

Edited by botanic
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 3 months later...

you still need to fix the following Error:

D:\Autoit\Easy Static IP Script.au3 (124) : ==> Subscript used with non-Array variable.:

For $1 = 1 to $ini[0]

For $1 = 1 to $ini^ ERROR

>Exit code: 1 Time: 6.264

Website: www.cerescode.comForum: www.forum.cerescode.comIRC: irc.freenode.net , Channel: #Ceres--------------------Autoit Wrappers, Great additions to your script (Must See) (By: Valuater)Read It Befor Asking Question Click Here...--------------------Join Monoceres's Forums http://www.monoceres.se--------------------There are three kinds of people: Those who make things happen, those who watch things happen, and those who ask, ‘What happened?’” –Casey Stengel
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...