5

I want to make a simple Windows desktop widget to turn on and off the internet proxy.

What is the simpler way?

3 Answers3

15

You can create a simple "widget" using Visual Basic scripts and batchs.

Example:

proxy_off.bat

echo off
cls
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
change_shortcut_on
exit

proxy_on.bat

echo off
cls
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
change_shortcut_off
exit

change_shortcut_off.vbs

Set sh = CreateObject("WScript.Shell")
Set shortcut = sh.CreateShortcut("C:\Users\%USERNAME%\Desktop\Proxy.lnk")
shortcut.TargetPath = "C:\Users\%USERNAME%\Proxy Settings\proxy_off.bat"
shortcut.IconLocation = "C:\Users\%USERNAME%\Proxy Settings\Icons\on.ico"
shortcut.Save

change_shortcut_on.vbs

Set sh = CreateObject("WScript.Shell")
Set shortcut = sh.CreateShortcut("C:\Users\%USERNAME%\Desktop\Proxy.lnk")
shortcut.TargetPath = "C:\Users\%USERNAME%\Proxy Settings\proxy_on.bat"
shortcut.IconLocation = "C:\Users\%USERNAME%\Proxy Settings\Icons\off.ico"
shortcut.Save

Instructions:

  • Create the folder "Proxy Settings" in "C:\Users\%USERNAME%\";
  • Create the folder "Icons" in "C:\Users\%USERNAME%\Proxy Settings\";
  • Insert the "on.ico" (any icon for proxy "On") and "off.ico" (any icon for proxy "Off") in "C:\Users\%USERNAME%\Proxy Settings\Icons";
  • Create the above files in "C:\Users\%USERNAME%\Proxy Settings\" (proxy_off.bat, proxy_on.bat, change_shortcut_off.vbs, change_shortcut_on.vbs);
  • Create a shortcut (Proxy.lnk) to "C:\Users\%USERNAME%\Proxy Settings\proxy_off.bat" in your Desktop;

Done! Very simple and effective. Now you can click on "Proxy.lnk" (the shortcut in your Desktop) to turn your proxy "On" and "Off".

Proxy On         Proxy Off

Proxy On   Proxy Off

On icon url: http://s30.postimg.org/sgoerz0od/image.png
Off icon url: http://s13.postimg.org/9zha38zkj/off.png

Lucas NN
  • 758
  • 5
  • 16
  • 1
    Also, make sure your .bat are not set to open by default with notepad. http://stackoverflow.com/questions/4905708/batch-files-dont-run-theyre-being-opened-with-notepad. I also set the `shortcut.WorkingDirectory="C:\Users\%USERNAME%\Proxy Settings" `to run the vbs programs and set a variable for the environmental variable `user=sh.ExpandEnvironmentStrings("%USERNAME%")` to use in the path names – jmzagorski Apr 22 '16 at 13:41
  • Important: `%USERNAME%` can NOT be used in the path names. I get the following error (image: https://i.stack.imgur.com/EbA5P.png). Instead, type out the actual folder name in place of that--ex: `gabriel`. Make sure you replace `%USERNAME%` *everywhere* it appears. Ex: `C:\Users\%USERNAME%\Proxy Settings\proxy_off.bat` --> `C:\Users\gabriel\Proxy Settings\proxy_off.bat` for me. – Gabriel Staples Jun 21 '17 at 02:19
  • I can't get the icon to show up either. It's just a white square. I even tried converting the png images above to .ico files using http://icoconvert.com/ – Gabriel Staples Jun 21 '17 at 02:36
  • 1
    @Lucas NN, I took it one step further. Also, I ran into several errors implementing your answer, and have resolved them here. See my answer here: https://stackoverflow.com/a/44752679/4561887. I have it creating a desktop shortcut and modifying the icon according to the Proxy state, using only one single .vbs file and no batch files, as well as bringing up a 1 sec timed popup windows to announce the new state each time you click the desktop shortcut. Thanks for your work. You were half the equation. – Gabriel Staples Jun 26 '17 at 03:27
2

In Windows 10 it seams that after execute the script you need to open proxy settings window for changes to take effect. So add the following lines:

proxy_off.bat

echo off
cls
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
change_shortcut_on
start /min ms-settings:network-proxy
taskkill /IM SystemSettings.exe /f
exit

proxy_on.bat

echo off
cls
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
change_shortcut_off
start /min ms-settings:network-proxy
taskkill /IM SystemSettings.exe /f
exit

ATM the setting window don`t start minimized.

Hristian Yordanov
  • 650
  • 1
  • 6
  • 25
1

Although this solution doesn't toggle the settings on its own, but it may be a shortcut to go to the right place quickly.

In windows 10 you can add a shortcut on your desktop, and in location field you enter:

ms-settings:network-proxy

This will direct you to the toggle proxy button. You then just need to click save.

A. Hassaan
  • 41
  • 4