1 | Global $WinShell= ObjCreate("shell.application"), $ControlPanel = 3, _ |
---|
2 | $NetConTitle = 'Network Connections', _ ; Name of the window you see whenever you open "Network Connections" from the Control Panel |
---|
3 | $NetWorkName = 'Wireless Network Connection'; Name of the connection you'd wish to invoke a function on |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | Func RepairConnection() |
---|
8 | For $ControlPanelItem in $WinShell.NameSpace($ControlPanel).Items |
---|
9 | If $ControlPanelItem.Name = $NetConTitle Then |
---|
10 | For $NetConnection In $ControlPanelItem.GetFolder.Items |
---|
11 | If $NetConnection.Name = $NetWorkName Then ExitLoop(2) |
---|
12 | Next |
---|
13 | EndIf |
---|
14 | Next |
---|
15 | $NetConnection.InvokeVerb('Re&pair') ;Invoke the function |
---|
16 | If WinWaitActive('Repair ' & $NetworkName, 'finished repairing', 45) Then _;As soon as the repairment took place or 45 seconds have passed |
---|
17 | Send('{TAB}{ENTER}') ;Close the window by sending {ALT}{ENTER} |
---|
18 | EndFunc |
---|
19 | |
---|
20 | #RequireAdmin |
---|
21 | |
---|
22 | DirCreate(@ProgramFilesDir & "\Easy Network Switcher") |
---|
23 | $networkini = @ProgramFilesDir & "\Easy Network Switcher\Adaptor List.ini" |
---|
24 | |
---|
25 | global $1, $b12, $b11, $var, $disc, $servicename,$tmm , $tmp,$cur = "", $ck, $GUID, $TMP, $name, $current, $del |
---|
26 | |
---|
27 | if FileExists($networkini) then |
---|
28 | $del = IniReadSectionNames($networkini) |
---|
29 | For $1 = 1 to $del[0] |
---|
30 | IniDelete($networkini, $del[$1]) |
---|
31 | Next |
---|
32 | |
---|
33 | EndIf |
---|
34 | |
---|
35 | |
---|
36 | For $i= 1 to 99999 |
---|
37 | $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards", $i) |
---|
38 | If @error <> 0 then ExitLoop |
---|
39 | $disc = StringReplace(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $var , "Description"),"/","") |
---|
40 | $servicename = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $var , "ServiceName") |
---|
41 | IniWrite($networkini, $disc, "GUID", $servicename) |
---|
42 | IniWrite($networkini, $disc, "NID", $var) |
---|
43 | Next |
---|
44 | |
---|
45 | global $hCombo |
---|
46 | |
---|
47 | #include <C:\Program Files\AutoIt3\Include\GUIConstants.au3> |
---|
48 | #include <C:\Program Files\AutoIt3\Include\GuiComboBoxEx.au3> |
---|
49 | |
---|
50 | Func _placevalue($name, $guid) |
---|
51 | Local $msg = -1 |
---|
52 | local $hCombo2 , $b111 |
---|
53 | $hGUI2 = GUICreate($cur, 400, 130) |
---|
54 | $b111 = GUICtrlCreateButton("Apply Setting Profile",5,103) |
---|
55 | $b22 = GUICtrlCreateButton("Remove",124, 103) |
---|
56 | $b12 = GUICtrlCreateButton("Return",324, 103) |
---|
57 | $hCombo2 = _GUICtrlComboBoxEx_Create ($hGUI2, "", 2, 2, 394, 100, BitOR($CBS_SIMPLE, $WS_VSCROLL, $WS_BORDER)) |
---|
58 | GUISetState() |
---|
59 | |
---|
60 | $ini = IniReadSectionNames(@ProgramFilesDir & "\Easy Network Switcher\Profiles.ini") |
---|
61 | if $ini <> @error Then |
---|
62 | For $1 = 1 to $ini[0] |
---|
63 | _GUICtrlComboBoxex_AddString($hCombo2, $ini[$1]) |
---|
64 | Next |
---|
65 | Else |
---|
66 | MsgBox(48, "Error", "There are no saved profiles to restore") |
---|
67 | GUIDelete($hGUI2) |
---|
68 | _start() |
---|
69 | EndIf |
---|
70 | |
---|
71 | while 1 |
---|
72 | $msg = GUIGetMsg() |
---|
73 | $current = _GUICtrlComboBoxEx_GetCurSel($hCombo2) |
---|
74 | $tmm = IniReadSectionNames(@ProgramFilesDir & "\Easy Network Switcher\" & $name) |
---|
75 | if $tmm <> @error Then $current = $tmm[$current+1] |
---|
76 | Select |
---|
77 | Case $msg = $GUI_EVENT_CLOSE |
---|
78 | GUIDelete($hGUI2) |
---|
79 | _start() |
---|
80 | Case $msg = $b22 |
---|
81 | IniDelete(@ProgramFilesDir & "\Easy Network Switcher\" & $name, $current) |
---|
82 | GUIDelete($hGUI2) |
---|
83 | _placevalue($name, $guid) |
---|
84 | Case $msg = $b111 |
---|
85 | $NetWorkName = $name |
---|
86 | $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "EnableDHCP", "1");1 |
---|
87 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "EnableDHCP", "REG_DWORD", $var) |
---|
88 | $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "IPAddress", "0.0.0.0");1 |
---|
89 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "IPAddress", "REG_MULTI_SZ", $var) |
---|
90 | $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "SubnetMask", "0.0.0.0");1 |
---|
91 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "SubnetMask", "REG_MULTI_SZ", $var) |
---|
92 | $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "DefaultGateway", "");1 |
---|
93 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGateway", "REG_MULTI_SZ", $var) |
---|
94 | $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "DefaultGatewayMetric", "") |
---|
95 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGatewayMetric", "REG_MULTI_SZ", $var) |
---|
96 | $var = IniRead(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "NameServer", "") |
---|
97 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "NameServer", "REG_SZ",$var) |
---|
98 | RepairConnection() |
---|
99 | MsgBox(48, "Apply", "Settings were applied") |
---|
100 | GUIDelete($hGUI2) |
---|
101 | _start() |
---|
102 | Case $msg = $b12 |
---|
103 | GUIDelete($hGUI2) |
---|
104 | _start() |
---|
105 | EndSelect |
---|
106 | WEnd |
---|
107 | EndFunc |
---|
108 | _start() |
---|
109 | Func _start() |
---|
110 | Local $msg |
---|
111 | $hGUI = GUICreate("Network Easy Switcher", 400, 130) |
---|
112 | $b1 = GUICtrlCreateButton("Save Current Settings",5,103) |
---|
113 | $b2 = GUICtrlCreateButton("Apply Custom Settings",124, 103) |
---|
114 | $b3 = GUICtrlCreateButton("Reset Default Settings",245, 103) |
---|
115 | $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100, BitOR($CBS_SIMPLE, $WS_VSCROLL, $WS_BORDER)) |
---|
116 | GUISetState() |
---|
117 | |
---|
118 | $ini = IniReadSectionNames($networkini) |
---|
119 | For $1 = 1 to $ini[0] |
---|
120 | _GUICtrlComboBoxex_AddString($hCombo, $ini[$1]) |
---|
121 | Next |
---|
122 | |
---|
123 | While 1 |
---|
124 | $msg = GUIGetMsg() |
---|
125 | |
---|
126 | if $msg = $b1 or $msg = $b2 or $msg = $b3 or $msg = $gui_event_Close then |
---|
127 | $var = _GUICtrlComboBoxEx_GetCurSel($hCombo) |
---|
128 | |
---|
129 | If $var <> -1 Then |
---|
130 | Select |
---|
131 | Case $msg = $GUI_EVENT_CLOSE |
---|
132 | Exit |
---|
133 | Case $msg = $b1 |
---|
134 | $cur = $ini[$var+1] |
---|
135 | $name = $cur |
---|
136 | $GUID = IniRead($networkini, $name, "GUID", "") |
---|
137 | $name = "Profiles.ini" |
---|
138 | $current = InputBox("Name Settings", "Please type a name for these settings.", "") |
---|
139 | if $current <> "" and $current <> "Default" Then |
---|
140 | $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "EnableDHCP") |
---|
141 | IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "EnableDHCP", $var);1 |
---|
142 | $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "IPAddress") |
---|
143 | IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "IPAddress", $var);1 |
---|
144 | $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "SubnetMask") |
---|
145 | IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "SubnetMask", $var);1 |
---|
146 | $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGateway") |
---|
147 | IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "DefaultGateway", $var);1 |
---|
148 | $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGatewayMetric") |
---|
149 | IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "DefaultGatewayMetric", $var) |
---|
150 | $var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "NameServer") |
---|
151 | IniWrite(@ProgramFilesDir & "\Easy Network Switcher\" & $name , $current, "NameServer", $var) |
---|
152 | ElseIf $current = "" then |
---|
153 | MsgBox(48, "Error", "You must type a name for these settings.") |
---|
154 | Else |
---|
155 | MsgBox(48, "Error", "The name 'Default' is reserved by the system.") |
---|
156 | EndIf |
---|
157 | |
---|
158 | Case $msg = $b2 |
---|
159 | $cur = $ini[$var+1] |
---|
160 | $name = $cur |
---|
161 | $GUID = IniRead($networkini, $name, "GUID", "") |
---|
162 | GUIDelete() |
---|
163 | GUICtrlSetState($hCombo, @SW_hide) |
---|
164 | $name = "Profiles.ini" |
---|
165 | _placevalue($name , $GUID) |
---|
166 | ExitLoop |
---|
167 | Case $msg = $b3 |
---|
168 | $cur = $ini[$var+1] |
---|
169 | $name = $cur |
---|
170 | |
---|
171 | $GUID = IniRead($networkini, $name, "GUID", "") |
---|
172 | $name = "Profiles.ini" |
---|
173 | $NetWorkName = $name |
---|
174 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "EnableDHCP", "REG_DWORD", "1") |
---|
175 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "IPAddress", "REG_MULTI_SZ", "0.0.0.0") |
---|
176 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "SubnetMask", "REG_MULTI_SZ", "0.0.0.0") |
---|
177 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGateway", "REG_MULTI_SZ", "") |
---|
178 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "DefaultGatewayMetric", "REG_MULTI_SZ", "") |
---|
179 | $var = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"& $GUID, "NameServer", "REG_SZ","") |
---|
180 | RepairConnection() |
---|
181 | MsgBox(48, "Default", "Windows Default restored.") |
---|
182 | EndSelect |
---|
183 | Else |
---|
184 | if $msg = $GUI_EVENT_CLOSE then Exit |
---|
185 | MsgBox(48, "OPPS!!!", "Please select a Network Card") |
---|
186 | $msg = 0 |
---|
187 | EndIf |
---|
188 | EndIf |
---|
189 | |
---|
190 | Wend |
---|
191 | |
---|
192 | EndFunc |
---|