Batch Script for IE & Firefox proxies
So, in the many endeavors I pursue at work for needless reasons, here’s something I hope someone else benefits from. We tend to lock down access on machines that are in public places, or have more than a few users. As we’re not quite fully migrated over to Microsoft Active Directory, and can’t manage Group Policy, theres no easy way to centrally manage browser proxy settings. We use browser proxy settings to limit the websites end users have access to on a machine ( to circumvent many wasted hours of cleaning up virus, spyware, and other junk). Browser proxy setting are super easy to mange with a .PAC file. IE can be managed by both a .INS and a .PAC file, but I’ve found the .PAC is more compliant throughout the majority of mainstream web browsers. We store a “restrict.pac” file on a web server to serve out proxy settings for IE and firefox to minimize the need to touch individual machines to add url’s to the the exception list. We just edit the one .PAC file and all machines configured to read that file are automatically updates (once the browser is restarted!). The problem is, we still have to touch each machine to setup the initial configuration to read the “restrict.pac” to auto configure the proxy settings. I recently developed a batch file that will setup both (IE and Firefox) browsers to use the “restrict.pac” file for proxy auto config settings. I haven’t had time to add conditionals if files already exist, but the script has been tested, and it doesn’t really matter if the files already exist in our environment. Feel free to use the code, and modify it in any way. If you find yourself needing something a little different, please comment. If you add to it, let me know! Here you go:
restrict.pac contents:
/Store info in variables for clean code var ALLOWED = "DIRECT"; //set the proxy server you want to redirect to var DISALLOWED = "PROXY services.valdosta.edu:80"; function FindProxyForURL(url, host) { //Add all exceptions for pages users need to hit here //all VSU pages if (shExpMatch(url,"*valdosta.edu/*")) {return ALLOWED;} //1Card online card office if (shExpMatch(url,"*blackboard.com/*")) {return ALLOWED;} //Bookstore e-commerce stuff if (shExpMatch(url,"*collegestoreonline.com/*")) {return ALLOWED;} //Off campus housing forum if (shExpMatch(url,"*freeforums.org/*")) {return ALLOWED;} //ADP related links if (shExpMatch(url,"*gafirst.esg.edu/*")) {return ALLOWED;} if (shExpMatch(url,"*adp.com/*")) {return ALLOWED;} //VSU Athletics if (shExpMatch(url,"*vstateblazers.com/*")) {return ALLOWED;} else { //redirect to proxy server for all other requests return DISALLOWED; } } // end of function
browserProxy.bat contents:
::Store info used to create user.js in variables
set var1=# Mozilla User Preferences
set var2=user_pref("network.proxy.autoconfig_url", "http://services.valdosta.edu/restrict.pac");
set var3=user_pref("network.proxy.type", 2);
set var4=user_pref("pref.advanced.proxies.disable_button.reload", false);
::concat each variable to create the user.js
echo %var1%> c:\\apps\user.js
echo %var2%>> c:\\apps\user.js
echo %var3%>> c:\\apps\user.js
echo %var4%>> c:\\apps\user.js
:: determine current user's firefox profile and set it to "var5"
for /f %%a in ('FINDSTR /r ".\.default" "%AppData%\Mozilla\Firefox\profiles.ini"') do set var5=%%a
set var5=%var5:~14%
:: Copy "user.js" to Firefox profile directory
COPY "c:\\apps\user.js" "%AppData%\Mozilla\Firefox\Profiles\%var5%\" >nul
:: create IE Proxy
Reg ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "AutoConfigUrl" /d "http://services.valdosta.edu/restrict.pac" /f
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.




Oh boy.
I tried many things to easily manage firefox proxy settings in a domain environment, but thanks to your post I stopped 5 minutes and thought about it: pac files is much easier.
Many thanks for putting me back on track. This script is awesome and so easy to use :]