Creating Relative Shortcuts in Windows

December 12, 2009

As a professional techie, I tend to carry a flashdrive around with various tools and applications pre-loaded on it. One of the most useful programs I have on my current drive is a portable version of Google Chrome.

However, due to the way that Chrome Portable installs itself on a flashdrive, the executable winds up buried inside the installation directory. Ideally, you should be able to place a shortcut to it on the root of your drive, but this is where you can run into trouble.

Because Windows shortcuts cannot contain relative paths, if the drive letter of your flashdrive changes (say, because you're using it on a different computer), your shortcut will no longer work. Needless to say, this can get annoying, but there are a few workarounds.

The Quick and Dirty Method

The easiest way to solve the problem is to use a batch file to launch the app instead of a shortcut. Assuming you're using Chrome Portable installed into the root of your flashdrive, your batch file should look like this:

cd "\GoogleChromePortable\"
start GoogleChromePortable.exe
exit

This basically tells Windows to look in the "GoogleChromePortable" folder, run the application itself, and then exit (so the DOS window closes).

Using a batch file to run an app is therefore better than a shortcut, because it will work regardless of the mapping (i.e., the letter) your flashdrive receives when you plug it in to a PC.

The Perfectionist's Method

Using batch files to launch programs works fine if you just have a few, but if you have more than ten or so apps on one drive, it can get annoying to hunt through all the batch files to find the one you want. It would be faster if you could just see each program's icon.

To get Chrome to running regardless of your flashdrive's assigned letter and use the appropriate icon, we need three things:

  • The batch file I described in the previous section
  • A batch file compiler (this one will do just fine)
  • An icon for the program in question (.ICO files are best)

Essentially what we're going to do is transform the batch file into it's own tiny application and give it a custom icon. Once you have the batch file compiler unzipped, just follow these steps:

  1. Run the Bat to Exe Converter.
  2. In the "Batch file" field, browse to the batch file we created earlier. This will act as the source code for our new mini-program.
  3. In the "Options" tab, select "Invisible application".
  4. In the "Version Information" tab, select the .ICO file you downloaded.
  5. Click Compile. The program will be created where you specified.

You should be able to see the resulting executable using your chosen icon. If you put it on the root of your flashdrive, running it will result in the opening of the app you created it for in the first place. Sweet!

Note: If you ever rename the folder that the original app is installed in, then the newly-created shortcut program will not work, because it'll still be pointing to the original directory, which no longer exists.

{ 1 comment… read it below or add one }

jdk March 4, 2010 at 8:45pm

thanks for the flashdrive shortcut tip with batch files.
it worked great.
instead of the compiler, I made 6 batch files, put them in a folder and then created shortcuts to the batch files and changed the icon to the actual program icon.

Reply

Leave a Comment

Previous post:

Next post: