Add icons and script files and readme

This commit is contained in:
Gabriel Staples
2021-05-25 15:32:43 -07:00
parent 77a629eb95
commit 16eae0e570
6 changed files with 122 additions and 0 deletions

BIN
Icons/off.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
Icons/off.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
Icons/on.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
Icons/on.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@@ -1,2 +1,48 @@
# Windows_Proxy_Toggler
A clickable icon on your Windows desktop to toggle your proxy on and off.
See [my answer on Stack Overflow][my_ans] for details and more info.
Here's what it looks like when the Proxy is OFF:
[![enter image description here][1]][1]
Here's what it looks like when the Proxy is ON:
[![enter image description here][2]][2]
Here's an example of the 1-second popup window that comes up whenever you click the shortcut icon to toggle the Proxy on/off.
[![enter image description here][3]][3]
Toggle your Proxy on and off by simply double-clicking the above desktop shortcut/icon.
By Gabriel Staples
www.ElectricRCAircraftGuy.com
Written: 21 June 2017
Updated: 25 June 2017
Updated and added to GitHub: 25 May 2021
# Instructions
# References:
1. See my answer on Stack Overflow here: [Batch File to disable internet options proxy server](https://stackoverflow.com/questions/18439373/batch-file-to-disable-internet-options-proxy-server/44752679#44752679)
1. (Someone else's answer) [Batch File to disable internet options proxy server](https://stackoverflow.com/questions/18439373/batch-file-to-disable-internet-options-proxy-server/27092872#27092872) - taught me how to use a .vbs script to toggle the Proxy on and off
1. (Someone else's answer) [Windows desktop widget to turn proxy on and off](https://stackoverflow.com/questions/26708347/windows-desktop-widget-to-turn-proxy-on-and-off/26708451#26708451) - taught me the ingenious technique on how to make a .vbs script act like a widget by creating a Windows shortcut and changing its icon each time you click on it.
1. Timed message boxes:
1. \*\*\*\*\*https://technet.microsoft.com/en-us/library/ee156593.aspx
1. https://stackoverflow.com/questions/14105157/automatically-close-msgbox-in-vbscript
Debug output:
- ex: Wscript.Echo "here is your message"
[1]: https://i.stack.imgur.com/IqKHI.png
[2]: https://i.stack.imgur.com/iap0E.png
[3]: https://i.stack.imgur.com/9vWES.png
[my_ans]: https://stackoverflow.com/questions/18439373/batch-file-to-disable-internet-options-proxy-server/44752679#44752679

76
toggle_proxy_on_off.vbs Executable file
View File

@@ -0,0 +1,76 @@
' This file is part of Windows_Proxy_Toggler: https://github.com/ElectricRCAircraftGuy/Windows_Proxy_Toggler
'
' Toggle your Proxy on and off via a clickable desktop shortcut/icon
' By Gabriel Staples, June 2017
' www.ElectricRCAircraftGuy.com
' See the README at the link above.
Option Explicit
'Variables & Constants:
Dim ProxySettings_path, VbsScript_filename
ProxySettings_path = "C:\Users\Gabriel\Proxy Settings"
VbsScript_filename = "toggle_proxy_on_off.vbs"
'sec; change this value to set how long the message box displays when you toggle the proxy setting
Const MESSAGE_BOX_TIMEOUT = 1
Const PROXY_OFF = 0
Dim WSHShell, proxyEnableVal, username
Set WSHShell = WScript.CreateObject("WScript.Shell")
'get the username string for use in path names, since trying to use the "%USERNAME%" variable
'directly in path names throws an error
username = WSHShell.ExpandEnvironmentStrings("%USERNAME%")
'Determine current proxy setting and toggle to opposite setting
proxyEnableVal = wshshell.regread("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
If proxyEnableVal = PROXY_OFF Then
TurnProxyOn
Else
TurnProxyOff
End If
'Subroutine to Toggle Proxy Setting to ON
Sub TurnProxyOn
'turn proxy on via a registry entry
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
'create/update desktop shortcut
CreateOrUpdateDesktopShortcut("on")
'notify user via an auto-timed popup box
WSHShell.Popup "Internet proxy is now ON", MESSAGE_BOX_TIMEOUT, "Proxy Settings"
End Sub
'Subroutine to Toggle Proxy Setting to OFF
Sub TurnProxyOff
'turn proxy off via a registry entry
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
'create/update desktop shortcut
CreateOrUpdateDesktopShortcut("off")
'notify user via an auto-timed popup box
WSHShell.Popup "Internet proxy is now OFF", MESSAGE_BOX_TIMEOUT, "Proxy Settings"
End Sub
'Subroutine to create or update a shortcut on the desktop
Sub CreateOrUpdateDesktopShortcut(onOrOff)
'create a shortcut
Dim shortcut, iconStr
Set shortcut = WSHShell.CreateShortcut("C:\Users\" + username + "\Desktop\Proxy On-Off.lnk")
'Set the target path (target file) to run when the shortcut is clicked
shortcut.TargetPath = ProxySettings_path + "\" + VbsScript_filename
'Set the working directory. This is necessary in case you ever make this shortcut call a batch
'(.bat) file, for instance, which in turn calls a .vbs script. In order to know where the .vbs
'script file/command is located, the shortcut must be operating in the working directory where
'the .vbs scripts are located. Otherwise, calls to the .vbs scripts from a .bat file this
'shortcut points to, for instance, won't work since their directories are not in the Windows
'%PATH% variable, and you'll get an error which states: "'name_of_vbs_script_file' is not
'recognized as an internal or external command, operable program or batch file."
shortcut.WorkingDirectory = ProxySettings_path
'Set the icon to associate with this shortcut
If onOrOff = "on" Then
iconStr = "on.ico"
ElseIf onOrOff = "off" Then
iconStr = "off.ico"
End If
shortcut.IconLocation = ProxySettings_path + "\Icons\" + iconStr
'Save the shortcut
shortcut.Save
End Sub