1

Portable applications are nice, simple programs that do not need to be installed on each and every computer that you are using.

Some software installers don't seem to do much except verify the environment and copy files to your hard drive. What I would like is my installed Windows apps on an external hard drive (or USB device) that can be carried around between computers. Settings and data should also be stored on the external hard drive so application changes (or game progress) can be preserved across computers.

Now, many Windows applications use the "AppData\Roaming" directory for certain settings and user data. This location seems to be stored in an environment variable. Is there a way to temporarily override the USERPROFILE or APPDATA location for just one application? This would be ideal, so that settings and data could be written to one location, instead of being copied between the external hard drive and host computer.

This goes beyond the idea of PortableApps(tm). I do not want to package applications or install some ridiculous runtime. Something nice and simple is all I'm looking for.

Any proposed solution must not cause any interference with other applications.

1 Answer 1

2

After a bit of testing, I have been able to confirm that you can override Windows environment variables in a command prompt, and their values will be inherited by other processes that are subsequently launched from that same command prompt. As such, we have the following batch file:

REM -- Path to the directory of this script (make sure to remove ending slash)
set CURRENT_DIR=%~dp0
REM -- Great example from Strawberry Perl's portable shell launcher:
if not "" == "%CURRENT_DIR%" if #%CURRENT_DIR:~-1%# == #\# set CURRENT_DIR=%CURRENT_DIR:~0,-1%

REM -- OVERRIDE the user environment variable to point to a portable directory
set USERPROFILE=%CURRENT_DIR%\Data

REM -- (Optional) Some programs do not use these environment variables
::set APPDATA=%CURRENT_DIR%\Data\AppData\Roaming>nul
::set ALLUSERSPROFILE=%CURRENT_DIR%\Data\AppData\Roaming>nul
::set PROGRAMDATA=%CURRENT_DIR%\Data\AppData\Roaming>nul

REM -- Start the application
start "" /D"%CURRENT_DIR%\MyAppDir" "myprogram.exe" "param 1" param_2 "param 3"

Each command prompt receives its own copy of the Windows environment variables when first opened, and these values can be changed in isolation from any other command prompts. Other process are unaffected by any of these changes.


On the other hand, permanent changes to environment variables can be made with setx.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .