📜 ⬆️ ⬇️

Portable-iziruemsya example Firefox

It started because of the friendly, dormant low-level holivar for many months “Linux vs. Windows "between me and our sys.admin.

Once a problem was raised about system security and user directories. There was a task to show that in Windows there is a full-fledged analogue of the Linux% home%.

Old wind users they know that user settings have started to be stored in a specially designed directory even in Windows 9x. But it was, to put it mildly, “not at all”. (Update: correct in the comments: it appeared in NT 3, and immediately with a good implementation.)
')
With the advent of NT 5 (Win2k, WinXP), where security was given more attention, all user profiles were stored in the same “Documents and Settings”. True, if desired, and direct hands it may be another directory, for example, “Users”.

At about the same time, global variables appeared to indicate the current user and his home directory. It seems inspired from the world of Linux. IMHO, nothing messy about it :)

You can find out the value of all global variables by running the SET command from the command line. For those who are completely in the tank: Win + R, type cmd, hit Enter, type set, hit Enter.

Microsoft's current guidelines recommend using global variables in order to find out where the program can store its settings. Unfortunately, many people ignore this, and some still stubbornly store the file with the settings in their directory. Hands would pootryvat.

We argued a little about user directories and forgot for the time being.

So far, once with the next update of FireFox on the official website, I have not found its portable version. I wanted a fresh and portable version. Then I remembered that FireFox is cross-platform, and most likely in Linux it stores the settings “where necessary”. And most likely in Windows it stores them there. And it finds out where to store “as it should be” - through global variables. Tea developers FireFox-a professionals.

So, we have Windows XP, the latest version of FireFox installed and the desire to get it portable.

Global variables are initialized when Windows starts and the user logs on. The new process gets the value of the global variables from the parent. The most common parent process is Explorer. But each process can override any global variable, but this new value of the variable will be available only to this process and its child processes. In the parent process, everything will remain the same.

You can override the global variable in the cmd shell using the same set command.
So you can override the variable in cmd, run the desired program, finish the work cmd. Profit!

The thought has just taken shape, and the hands have already begun to sculpt the script. To begin, find out where FireFox stores our settings / profiles. It turned out
c: \ Documents and Settings \ Guest \ Local Settings \ Application Data \ Mozilla \
and
c: \ Documents and Settings \ Guest \ Application Data \ Mozilla \

The Firefox profile itself is here.
c: \ Documents and Settings \ Guest \ Application Data \ Mozilla \ Firefox \ Profiles \
and I called it "6rynxm6u.default". Random combination of characters. You may have another.

In the FireFox directory, we create the folder “toxicdream” (well, or as you wish) - this will be ours, thus% home%. Inside it, create "\ Local Settings \ Application Data \" and "\ Application Data \ Mozilla \". The Mozilla catalogs found above are transferred to the appropriate ones.

We look at which Windows variables can help us:
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\\Application Data
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\
USERNAME=
USERPROFILE=C:\Documents and Settings\


Let's try to do a little blood - overlap only APPDATA and see what happened. Create
in the Firefox directory, the file “firefox.cmd” with the text

 %~d0% cd %~dp0% set APPDATA=%~dp0%toxicdream\Application Data start firefox.exe 


The first two lines indicate that you need to switch to the disk and go to the directory where the file “firefox.cmd” itself is located, so that the working directory for the FireFox being launched is this directory.
We start. Well, almost it turned out - the user profile is loaded.

With "Local Settings" will have to tinker. After overlapping USERPROFILE and USERNAME, the chanterelle still climbs in the wrong direction to where it was told. It is necessary to block still HOMEPATH and accordingly HOMEDRIVE

 %~d0% cd %~dp0% set APPDATA=%~dp0%toxicdream\Application Data set HOMEDRIVE=%~d0% set HOMEPATH=%~p0%toxicdream set USERNAME=toxicdream set USERPROFILE=%~dp0%toxicdream start firefox.exe 


Well, so surely we will block another ALLUSERSPROFILE and TEMP / TMP. The final script is

 %~d0% cd %~dp0% set ALLUSERSPROFILE=%~dp0%toxicdream set APPDATA=%~dp0%toxicdream\Application Data set HOMEDRIVE=%~d0% set HOMEPATH=%~p0%toxicdream set TEMP=%~dp0%toxicdream\Local Settings\Temp set TMP=%~dp0%toxicdream\Local Settings\Temp set USERNAME=toxicdream set USERPROFILE=%~dp0%toxicdream start firefox.exe 


I remind you - this is for Windows 5.x, that is, Windows 2000, Windows XP and Windows 2003.
Script text for Win7:

 %~d0% cd %~dp0% set ALLUSERSPROFILE=%~dp0%toxicdream set APPDATA=%~dp0%toxicdream\Application Data set HOMEDRIVE=%~d0% set HOMEPATH=%~p0%toxicdream set LOCALAPPDATA=%~dp0%toxicdream\Application Data\Local set TMP=%~dp0%toxicdream\Application Data\Local\Temp set TEMP=%~dp0%toxicdream\Application Data\Local\Temp set USERNAME=toxicdream set USERPROFILE=%~dp0%toxicdream start firefox.exe 


Well, now everything works like a clock. You can even update with all the settings saved. And do not wait for anyone or suffer with ThInstall and his ilk. True, another effect pops up here: all (or almost all) programs launched from our FireFox will use our “toxicdream” directory for their work. Therefore, do not be surprised if suddenly, for example, Download Master starts to show a list of downloads, this is the case, then this way.

PS
In Viste and Seven, the Firefox profile is stored elsewhere. Plus, they also added a variable for that “Local Settings”, or rather, “Local” -% LOCALAPPDATA%.

It is necessary to move files from “Local Settings” to “Application Data \ Local” at each system change.

You can also write all this in the script. Unfortunately, I do not have Win7 at hand now, so I leave it for the next enthusiasts to finalize it.

For starters: you can find out the version of Windows with the command ver. There is a small rake - the output of the command differs from version to version, and maybe from the system language. The code that identifies the version unequivocally:

 echo off for /f "usebackq tokens=2 delims=[]" %%i in (`ver`) do set osver=%%i for /f "usebackq tokens=2 delims=. " %%i in (`set osver`) do set osver=%%i if %osver% == 6 ( echo Win7 or Vista ) else if %osver% == 5 ( echo W2k or XP ) pause 


UPD 1
> running firefox like this: firefox -profile “E: \ myprofile” we achieve our goal. That is, you need to create a shortcut and everything will work as it should.
Minuses:
- hard binding to the tracks
- create / modify label
- garbage in "Local Settings"

UPD 2
> portable firewall is not just google fast, but very fast - mozilla-russia.org/products/firefox/ - once and portableapps.com/apps/internet/firefox_portable - two.
Minuses:
- not always the latest version
- extra process in memory
- Sometimes there are problems when updating, for example, I personally had when upgrading to Windows 7

UPD 3
> Why on the Fire Fox blog?
It seemed to me for the users of Ognelis to be more interesting.
Windows blog is too basic.

Thanks for the pluses :) The next post will be about the internal structure of FireFox, or rather, about what, how and where it stores.

Source: https://habr.com/ru/post/111704/


All Articles