Do you need to test your code in older versions of Firefox or Google Chrome? Would you like to buy a new laptop and be ready to code right away? Would you like to play a Steam game on an airplane? Do you prefer your apps to not be tied to a particular machine? Those are some of the problems solved by portable apps.
There are two definitions of portable when referring to a program. One definition is a program that can run in several operating systems, e.g. programs written in Java or Python. The other definition is that a portable app is one that doesn't need to be installed on the machine. It can be run from a USB or external drive. This second definition is the one used in this article.
You will learn about portable apps, how to get started with them, and how to create scripts to make some apps portable.
You can find portable apps at PortableApps.com. If you use that site, I recommend you install their PortableApps.com platform because it makes it easy to upgrade the apps and knows when there are new versions available. You don't have to run it to run the apps. When you run it it displays which apps have an update available and you can update them from there. Another site with portable apps is PortApps (e.g. Slack, Discord, Skype, WhatsApp).
Apps that run other apps need a bit of work to set up. Later in the article, you will learn some techniques to make regular apps portable.
It's easy to encrypt and backup portable apps and their data because they are self-contained. For encryption, use Veracrypt. You need administrative privs on your machine, but it's free, open source, and portable. It allows you to encrypt the whole drive or create volumes. A volume is an encrypted file that mounts as if it were an external drive. Create a volume that's big enough to store all your apps and data. Leave enough space in the rest of the external drive for a copy of Veracrypt and other data. Learn how to create a volume in this Veracrypt Beginner Tutorial.
Create a backup of your encrypted volume. To copy apps from one machine to another I recommend you use robocopy commands because it can handle long paths that regular copy and paste can't handle.
Portable browsers allow you to run older versions of the same browser. Also, websites like StackEdit (WYSIWYG for markdown) are even more useful now because they store your data in your browser and your browser is now portable.
GOG, itch.io, and Humble Bundle offer many games that are DRM-free and can be played in a portable way or can be made portable. Even some Steam can be made portable if they don't need to call the Steam api.
Some apps can be made portable if they don't depend on apps that can't be made portable and don't integrate with the operating system. An app that only creates registry environment variables and/or files on the machine can be made portable by moving its data off the machine. We can create scripts to copy its data to the machine before the app runs, and move its data out of the machine when it terminates.
For example, some Steam games can be portable. To see if a Steam game can be made portable close Steam and remove the steam_api.dll files from the game directory (look inside the Steam\steamapps\common folder the games). Run the game's executable file and see if the game runs without opening Steam. If it runs without that file it can probably be made portable, but your data won't sync to the Steam servers and you may have to copy its save data from the users' AppData folders, the user's Document folder, or the registry.
Run WhatChanged to determine which files and registry entries were created or changed by the game. Then create scripts to move that data off the machine when we are done running the game, and to copy it back to the machine before we start the game.
For example, Magicite saves its data in the registry. It's in HKEY_CURRENT_USER\SOFTWARE\SmashGames\Magicite
We can export the data using this script:
reg export "HKEY_CURRENT_USER\SOFTWARE\SmashGames\Magicite" MagiciteSavedData.reg
Delete it from the registry using this script (add /f at the end if you don't want it to ask you for confirmation):
reg delete "HKEY_CURRENT_USER\SOFTWARE\SmashGames\Magicite"
And place it back in the registry using this script:
reg import MagiciteSavedData.reg
Do not run those scripts if you have not worked with the registry before because a typo can really mess up your machine.
If you downloaded the PortableApps.com platform to manage your apps and installed Java from it, you may have noticed that it placed _Java_inside a CommonFiles folder. That folder is used for applications that are needed by other applications to run.
If the portable app was not from PortableApps.com, you can try to modify it to match the PortableApps.com specifications. If that looks like a lot of work, you can just create temporary environment variables so it knows where are the apps it needs to run. That's how we will let Visual Studio Code know where to find Node.js and npm. Let's go through the technique.
Download the .zip version of Portable Node.js and unzip it inside PortableApps/CommonFiles/nodejs folder (it can be unzipped anywhere, but that's the directory we will use in this example). You will need to create that nodejs folder. Download the .zip verision of Visual Studio Code and unzip it inside a PortableApps/CommonFiles/VisualStudioCode folder (it could be unzipped anywhere, but that's the directory we will use in this example). You will need to create that VisualStudioCode folder. Then, create a data folder inside the VisualStudioCode folder:
| |- Code.exe (or code executable)
| |- data
| |- ...
All of Visual Studio Code's settings, preferences, extensions, session state, etc are stored in that data folder. To upgrade Visual Studio Code, download the new version and move your data folder into the new version.
Create a batch file inside PortableApps/CommonFiles that will contain all the environment variables needed. Let's call it _EnvironmentVariables.bat:
REM %~dp0 specifies the current directory.
REM Add the variables before %PATH% so they take precedence.
From now on use that batch file to set the environment variables of all the portable apps that require an environment variable to be set.
Next, create a batch file to run Visual Studio Code. Let's call it _RunVisualStudioCode.bat:
REM setlocal (see https://ss64.com/nt/setlocal.html)
REM sets temporary local environment variables.
REM The /D switch changes both drive and directory
cd /D %~dp0\VisualStudioCode\RUN
REM Pause so we can see if there was an error message
REM done with the temporary environment variables
Run _RunVisualStudioCode.bat whenever you need to run Visual Studio Code and it will know where to find Node.js and npm. Use this technique for any portable app that needs to know where is Java, Node.js, etc.
Unfortunately, not every app can be easily made portable. Some apps depend on apps that can't be made portable, or integrate with the operating system. In those cases, you could try to just make its saved data portable or install the app in a virtual machine using Portable-VirtualBox. If you decide to use Portable-VirtualBox you can upgrade Portable-VirtualBox and its Extension Pack by following the instructions from jlfarinha on Sep 8, 2017.
I realize this way of running apps is not for everyone because one has to take care of some low-level details, but having your apps, app settings, and data not tied to a particular machine is very liberating.
You learned about portable apps and some techniques to make apps portable:
If this article piqued your interest and you want to go further with portable apps, you can try to package your favorite app. Read about it in PortableApps.com Development.