How do I change Firefox Proxy settings via command line on windows xp/2k?
Thanks
How do I change Firefox Proxy settings via command line on windows xp/2k?
Thanks
I don't think there is a direct way to set the proxy (on Windows).
You could however install an add-on like FoxyProxy, create several configurations for different proxies and prior to starting FireFox move the appropriate configuration to the correct folder in your FireFox profile (using a batch file).
I don't think you can. What you can do, however, is create different profiles for each proxy setting, and use the following command to switch between profiles when running Firefox:
firefox -no-remote -P <profilename>
The proxy setting is stored in the user's prefs.js
file in their Firefox profile.
The path to the Firefox profile directory and the file is:
%APPDATA%\Mozilla\Firefox\Profiles\7b9ja6xv.default\prefs.js
where "7b9ja6xv
" is a random string. However, the directory of the default profile always ends in ".default". Most of the time there will be only one profile anyway.
Setting you are after are named "network.proxy.http
" and "network.proxy.http_port
".
Now it depends on what technology you are able/prepared to use to change the file.
P.S.: If this is about changing the proxy settings of a group of users via the logon script or similar, I recommend looking into the possibility of using the automatic proxy discovery (WPAD) mechanism. You would never have to change proxy configuration on a user machine again.
The easiest way to do this is to configure your Firefox to use a PAC with a file URL, and then change the file URL from the line command before you start Firefox.
This is the easiest way. You don't have to write a script that remembers what path to prefs.js is (which might change over time).
You configure your profile once, and then you edit the external file whenever you want.
Thank very much, I find the answers in this website.
Here I refer to the production of a cmd file
by minimo
cd /D "%APPDATA%\Mozilla\Firefox\Profiles" cd *.default set ffile=%cd% echo user_pref("network.proxy.http", "192.168.1.235 ");>>"%ffile%\prefs.js" echo user_pref("network.proxy.http_port", 80);>>"%ffile%\prefs.js" echo user_pref("network.proxy.type", 1);>>"%ffile%\prefs.js" set ffile= cd %windir%
there is a way to add username and password of that proxy on the setting file ?
Just wanted to post the code in a cleaner format... originally posted by sam3344920
cd /D "%APPDATA%\Mozilla\Firefox\Profiles"
cd *.default
set ffile=%cd%
echo user_pref("network.proxy.http", "148.233.229.235 ");>>"%ffile%\prefs.js"
echo user_pref("network.proxy.http_port", 3128);>>"%ffile%\prefs.js"
echo user_pref("network.proxy.type", 1);>>"%ffile%\prefs.js"
set ffile=
cd %windir%
If someone wants to remove the proxy settings, here is some code that will do that for you.
cd /D "%APPDATA%\Mozilla\Firefox\Profiles"
cd *.default
set ffile=%cd%
type "%ffile%\prefs.js" | findstr /v "user_pref("network.proxy.type", 1);" >"%ffile%\prefs_.js"
rename "%ffile%\prefs.js" "prefs__.js"
rename "%ffile%\prefs_.js" "prefs.js"
del "%ffile%\prefs__.js"
set ffile=
cd %windir%
Explaination: The code goes and finds the perfs.js file. Then looks within it to find the line *"user_pref("network.proxy.type", 1);"*. If it finds it, it deletes the file with the /v parameter. The reason I added the rename and delete lines is because I couldn't find a way to overwrite the file once I had removed the proxy line. I'm sure there is a more efficient/safer way of doing this...
cd /D "%APPDATA%\Mozilla\Firefox\Profiles" cd *.default set ffile=%cd% echo user_pref("network.proxy.http", "%1");>>"%ffile%\prefs.js" echo user_pref("network.proxy.http_port", 3128);>>"%ffile%\prefs.js" echo user_pref("network.proxy.type", 1);>>"%ffile%\prefs.js" set ffile= cd %windir%
This is nice ! Thanks for writing this. I needed this exact piece of code for Windows. My goal was to do this by learning to do it with Linux first and then learn the Windows shell which I was not happy about having to do so you saved me some time!
My Linux version is at the bottom of this post. I've been experimenting with which file to insert the prefs into. It seems picky. First I tried in ~/.mozilla/firefox/*.default/prefs.js but it didn't load very well. The about:config screen never showed my changes. Currently I've been trying to edit the actual Firefox defaults file. If someone has the knowledge off the top of their head could they rewrite the Windows code to only add the lines if they're not already in there? I have no idead how to do sed/awk stuff in Windows without installing Cygwin first.
The only change I was able to make to the Windows scripts is above in the quoted part. I change the IP to %1 so when you call the script from the command line you can give it an option instead of having to change the file.
#!/bin/bash
version="`firefox -v | awk '{print substr($3,1,3)}'`"
echo $version " is the version."
# Insert an ip into firefox for the proxy if there isn't one
if
! grep network.proxy.http /etc/firefox-$version/pref/firefox.js
then echo 'pref("network.proxy.http", "'"$1"'")";' >> /etc/firefox-$version/pref/firefox.js
fi
# Even if there is change it to what we want
sed -i s/^.*network.proxy.http\".*$/'pref("network.proxy.http", "'"$1"')";'/ /etc/firefox-$version/pref/firefox.js
# Set the port
if ! grep network.proxy.http_port /etc/firefox-$version/pref/firefox.js
then echo 'pref("network.proxy.http_port", 9980);' >> /etc/firefox-$version/pref/firefox.js
else sed -i s/^.*network.proxy.http_port.*$/'pref("network.proxy.http_port", 9980);'/ /etc/firefox-$version/pref/firefox.js
fi
# Turn on the proxy
if ! grep network.proxy.type /etc/firefox-$version/pref/firefox.js
then echo 'pref("network.proxy.type", 1);' >> /etc/firefox-$version/pref/firefox.js
else sed -i s/^.*network.proxy.type.*$/'pref("network.proxy.type", 1)";'/ /etc/firefox-$version/pref/firefox.js
fi
utterly brilliant ! I was in need of that script to emulate a localhost vs "real" website at hand with a simple .bat file. That was needed especially when you want to test a complicated mulilingual .htaccess... Actually i override the routing rules , first trough the "hosts" file (i'm talking windows) and then desactivate the proxy when testing the localhost version (yes , i'm behind a proxy) Thank you so much for the tip !!