Portable file association for USB sticks?

5,445

Solution 1

I use a lot of portable apps, and I use two programs especially made for this. They both do the same thing, but in different ways.

eXpresso (made using AutoHotkey) intercepts mouse clicks and changes the action to open whichever program that you associate the file type with.

Portable File Associator (made using AutoIt) makes file association entries in the HKCU registry hive, which does not need admin rights, and it can be set to remove them when the program is exited. I prefer this one, as it can also be made to make the entries and then exit without removing the associations, which is useful on my own computers (the instructions for more advanced use are in a file somewhere in the program folder). The way it works also allows you to define icons to the file types. When you download this program, the password for the archive file is in the file name.

Programs made using AutoIt and AutoHotkey can sometimes get flagged as viruses by anti-virus programs, as viruses have been made using them, but these programs are totally safe.

Solution 2

Here is what I use, which might be overcomplicated:

  • Have a batch file on the USB drive that maps its folder to the Q: or another drive letter (subst Q: "%~dp0" basically)
  • Use a portable explorer with custom file associations. I use FreeCommander; under “Extras, Preferences, Programs” you can set custom programs to open when hitting F4 on your files, depending on their extension. I have mapped 7z,zip,tar,etc. to 7zip-portable for example. So all you have to do is set the editor to Q:\7z-portable\7zportable.exe and that's all.

Solution 3

You can use the standard assoc command in a batch script (.bat) to save, set and reset file associations.

The assoc command can display and association, for example, in a Command Prompt (cmd) :

image1

The command can also set a file-association :

image2

You can create the following two .bat files on the root folder on the USB disk (or elsewhere). These batch files require the presence in the same folder of a file named prefix that you create only once using notepad and typing the string "assoc ", without the quotes and with the ending blank and (very important) without pressing Enter (so it doesn't have an end-of-line).

The first .bat file we will call myapps.bat, and whose purpose will be to assign the new file association, after creating another restore.bat file that you will use before ejecting the USB disk in order to restore the old file associations.

An example myapps.bat to set the file associations of html, abab and htm to myprog1.exe etc. :

@echo off
echo @echo off >restore.bat
cmd /q /c doassoc html "%cd%\myprog1.exe"
cmd /q /c doassoc abab "%cd%\myprog2.exe"
cmd /q /c doassoc htm "%cd%\myprog3.exe"
del ftemp1
del ftemp

The variable %cd% stands for the current directory, but you can also use %cd:~0,2% which will give you the current disk (for example G:) together with any other relative file specification on the disk.

The doassoc.bat file which does the work for one file association will contain :

echo assoc .%1= >ftemp1
assoc .%1 >nul
IF %ERRORLEVEL% NEQ 0 goto notfound
assoc .%1 >ftemp
copy /b /y prefix+ftemp ftemp1 >nul
:notfound
copy /b /y restore.bat+ftemp1 restore.bat >nul
assoc .%1=%2

An example of the result when running myapps.bat followed by restore.bat is :

image3

Solution 4

I assume you are using software packaged by PortableApps.com. While we are waiting for file associations to be implemented, Xenon Portable may be the easiest solution.

You can use the GUI to manage file associations...

settings

editor

or you can edit the XenonPortable\Data\settings\assoc.ini configuration file.

The format is as follows:

[<extension>]
icon=<image>.ico
exe=|XEDIR|\<path>

Where <path> is relative to the XenonPortable directory.

Solution 5

You could use the XYplorer portable file manager. Its latest version is commercial, but the last freeware version is still available from here.

Its Portable File Associations can associate file extensions with applications and even with user-written scripts :

image

Share:
5,445

Related videos on Youtube

auroranil
Author by

auroranil

Updated on September 18, 2022

Comments

  • auroranil
    auroranil almost 2 years

    I have a usb stick with PortableApps that I carry around between different places.

    But one thing that annoys me, is when I open a file (such as *.flv or *.html), either Windows says it is unsupported or it opens a program that I do not want to use (eg Win.M.P.), while I have the "correct" program (that I want to use) on my USB drive.

    Is there any portable program that can associate my "unsupported" files when I execute just one/a few program/s?

    (I was about to use ftype and assoc on a batch file, but it requires administrator privileges, so that doesn't seem to be the best solution.)

  • auroranil
    auroranil over 12 years
    Adding +1 for good answer. But is it possible to do it in a simpler way? Or can you explain your answer in more detail of how/why map the folder to `Q:` or another drive?
  • Oliver Salzburg
    Oliver Salzburg over 12 years
    @user824294 I would assume this allows him to keep his associations static. They always go to Q:\myprogram.exe instead of different_every_time:\myprogram.exe
  • auroranil
    auroranil over 12 years
    Awesome. But could you verify that it does not require admin privileges? +50 if it does not.
  • harrymc
    harrymc over 12 years
    Sorry, I was testing this with UAC disabled. assoc does require admin rights.
  • harrymc
    harrymc over 12 years
    I would delete this, except that it may still be useful for somebody. Don't bother to undervote.
  • Benoit
    Benoit over 12 years
    @Oliver Salzburg: I couldn't say it better.
  • Karan
    Karan over 11 years
  • Keyslinger
    Keyslinger over 11 years
    The download link is broken. Any idea where I can find a working copy?
  • Stevoisiak
    Stevoisiak over 7 years
    Unfortunately, as of Windows 8 this solution no longer works
  • Duarte Farrajota Ramos
    Duarte Farrajota Ramos almost 7 years
    This is unnecessary, you can specify custom file associations in FreeCommander using relative paths to the Freecommander executable, that means they are totally resilient to drive letter changes. You don't need the batch file shenanigans at all.