April 30, 2019

Portable Apps

By Alfredo Liu-Perez

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.

The good

  • You can have different versions of the portable app in your machine. This is useful for testing older versions of browsers.
  • They can run from a USB or external drive without leaving files or registry entries on the machine that runs them.
  • They can be copied to another machine and run with the same settings they had when they were copied.
  • The app and all its data can be easily encrypted.

The bad

  • A USB or external drive is easier to misplace, break, or forget than a laptop. You should backup your apps and data.
  • There may not be an update available for some apps at the same time as there is one for the non-portable version. This applies to apps from PortableApps.com.
  • It takes some effort to set up and run portable apps that call other portable apps, e.g. setting up Visual Studio Code to run Node.js and npm.
  • They are not meant to be run by multiple users on the same machine.
  • Not all apps are portable or can be made portable, e.g. those that integrate with the OS.

How to get started

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.

Security

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.

To manage your passwords on the cloud you can use LastPass. To manage them locally you can use KeePass.

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.

Some useful portable apps by category.

Office and Utilities

  • Libre Office and Apache's OpenOffice are portable replacements of Microsoft Office.
  • Notepad++ is a popular text editor with syntax highlighting that has a useful macro recording and playback capability.
  • Sumatra PDF is a PDF, DjVu, cbz, and cbr viewer.
  • WinMerge is a file comparison and differencing tool.
  • 7-Zip is a file compression and decompression utility.

Browsers

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.

Graphics and video

  • VLC Media Player, an audio and video player that plays every audio and video format.
  • Blender, a 3D modelling, animation, rendering, post-production, playback app.
  • Gimp, an alternative to Photoshop.
  • Inkscape, a vector graphics editor.

Software Development

Games

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.

How to make some apps portable

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 steamapi.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 HKEYCURRENT_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

Don't run those scripts if you have not worked with the registry before because a typo can really mess up your machine.

What if one portable app needs to run another one?

If you downloaded the PortableApps.com platform to manage your apps and installed Java from it, you may have noticed that it placed Javainside 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:

    |- VisualStudioCode
    |   |- 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.
    set NODE_HOME=%~dp0nodejs
    set NPM=%~dp0nodejs\node_modules\npm
    set VS_CODE=%~dp0VisualStudioPortable

    REM Add the variables before %PATH% so they take precedence.
    set PATH=%NODE_HOME%;%NPM%;%NPM%\bin;%PATH%;

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. 
    setlocal
    call %~dp0\_EnvironmentVariables.bat

    REM The /D switch changes both drive and directory    
    cd /D %~dp0\VisualStudioCode\RUN
    code .

    REM Pause so we can see if there was an error message
    pause

    REM done with the temporary environment variables
    endlocal

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.

What if I can't make my apps portable?

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.

Last remarks

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:

  • Creating temporary environment variables for portable apps to know where other portable apps are located.
  • Copying the app data to the machine when the app starts, and moving it out of the machine when the app terminates.
  • Importing registry entries to the machine when the app starts, and exporting them when the app terminates.

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.


Alfredo Liu-Perez - Software Consultant

About Alfredo Liu-Perez

Alfredo is a consultant at Centare with over 20 years of experience in software development who likes to help clients meet their goals. He also has a borderline unhealthy obsession with portable apps.