USB Applications › Batch files
The programs of a portable kit cannot be started by shortcut icons, since Windows shortcut icons support only absolute paths,
i.e., full paths starting with a drive letter (
C:\Program Files\KeePass\KeePass.exe), and not relative paths,
i.e., paths that work relative to the directory from which a command is issued.
A portable USB kit needs relative paths, since the keydrive letter will vary depending on the system.
The system will give to the keydrive the first available drive letter.
This can be anything from
The most basic way to start a program is to look for its executable and double-click on it.
E.g., to start KeePass, look for
KeePass.exe and double-click on it.
If you use more than a couple of programs, this is not convenient.
The most convenient solution is a launcher for USB apps,
or, for keyboard lovers, AutoHotkey.
Another basic and simple solution is batch files.
Batch files work in any Windows computer, with no need for additional programs.
Let’s say you have a folder in the keydrive for your USB programs: “Apps”, and that all your portable apps are in child folders of this folder.
Open Notepad and paste this (the example is for IrfanView):
- Save the file as “IrfanView.bat” (do not use the extension txt) in the rood directory of the keydrive
- Repeat for all programs you want to use
- Plug in the keydrive and double-click on a batch file to start the application it points to
Spaces in paths
In general, it is good to avoid spaces in paths. If the path contains spaces, e.g. ..\Easy Cleaner\easyclea.exe, enclose it in double quotes: "..\Easy Cleaner\easyclea.exe", or Windows will think the path ends at the first blank space, and will interpret the rest as a nonsensical command.
Dots, double dots & backslashes
- A dot represents the current directory. Usually this can be ommitted.
- A double dot represents the parent directory, or the current directory if there is no parent.
- A backslash at the start of a path without a single or double dot in front represents the root directory of the drive. If you use this, you will lose relativity. The batch files will work fine in your keydrive in any computer, but won’t work at a different hierarchical level, e.g., if you keep a backup of your keydrive in C:\Mykeydrive, and want to work from there.
- If a path that starts without a dot, double dot, or backslash, the first directory is supposed to be a child of the current directory. See the script below.
If you usually work with the same set of programs, you can make just one batch file to start them all at once:
@echo off start apps\freecommander\freecommander.exe start apps\portablefirefox\portablefirefox.exe start apps\skype\skype.exe /datapath:apps\skype\skypedata /removable start apps\win32pad\win32pad.exe
Give it a name, say “Programs.bat” and save it in the root directory of the keydrive. Double-click on it to start your programs. This example also illustrates the concept of the batch file: a file by which a batch of commands is executed at once.