USBProgram - User Command to run programs from USB

Please read this entire post before proceeding!



The USBProgram user command is designed to help reliably execute programs from within Directory Opus running from a USB flash drive. The alias syntax within Directory Opus already provides a means for executing programs from a USB flash drive, but the USBProgram user command goes a little bit beyond this to add the additional features noted below.

  1. It ensures that shell programs launched on Windows Vista receive the system focus.

    Under some circumstances, running a shell program from within Directory Opus (I believe from within an MS-DOS Batch Function) on Windows Vista (and I presume Windows 7 as well) will cause the shelled program to open below Directory Opus. As I understand things, this is not a bug in Directory Opus, but a feature of Windows Vista. The USBProgram user command launches shell programs using a VBScript function which supports setting the system focus to the launched application.

  2. It provides the ability to run command line utilities from within a pre-configured command console (cmd.exe).

    The command console's title will automatically be set to the program executable name passed to USBProgram. The command console's system %PATH% environmental variable will also be updated to include the program folder for the utility on the USB flash drive.

  3. It provides the ability to specify a working directory for the program in the invoking command line. There is also some logic branching and an automatic fallback queue which ensures a known working directory.

    This feature is especially useful on Windows Vista (and I presume Windows 7 as well) where opening a command console running with elevated privileges results in a current directory of %HOMEDRIVE%%HOMEPATH%, which is the current user's profile folder. This could present data loss risks with some utilities, so USBProgram defaults to the %TEMP% folder instead. The fallback folder queue order is:

    1. WORKINGDIR/K - The working directory explicitly specified in the invoking command line (if any).
    2. {sourcepath} - The source path of the active lister window (this only covers when a lister is open, and then only when a lister is open to a file system folder, not a virtual folder).
    3. %TEMP% - The current Windows user's temporary folder.
  4. A safety feature that helps ensure that USBProgram will only launch programs when executed from Directory Opus running from a USB flash drive. This ensures that when Directory Opus is running from a PC installation that a misclick on a toolbar button designed to only be run from USB will have no adverse effects on your system.

The command template is:


RELATIVEPATH/K/A Use this required keyword to pass the relative folder path from your programs folder to the program on your USB flash Drive.

PROGRAMEXE/K/A Use this required keyword to specify the program executable file name to run from the USB flash drive.

WORKINGDIR/K Use this optional keyword to specify a working directory for the program executable. If this folder is not specified or cannot be found, then the Opus source folder will be used. If there is no Opus source folder, such as when running from an Opus hotkey with no lister window open, then the %TEMP% folder will be used instead.

PARAMETERS/K Use this to specify any parameters to be passed to the program executable.

USECMD/S Use this switch to indicate that the program should be run within a command console (cmd.exe). USBProgram handles program execution differently for command line and shell programs. Command line programs are run within a cmd.exe console and USBProgram will append the specified program's path to the user's %PATH% environmental variable, which will remain in-effect for the duration of that command console (and for any child consoles opened from within it).

Setting the path like this allows the user to (re)run a command line executable within the cmd.exe console, without being required to specify a fully qualified executable path.


  1. Directory Opus v9.x or greater.
  2. VBScript must be enabled on the Windows PC running USBProgram.
  3. USBProgram expects that one folder on your USB flash drive is the main programs folder, under which all USB programs or suites reside directly, or more likely, have their own subfolder.

    By default, USBProgram is configured to use the folder named "PortableApps" in the root of the USB flash drive. This is the convention for the menu and suite. (See Adding Other Apps to the Menu.) However, you may use any main program folder path you want; just remember that all Directory Opus command lines invoking the USBProgram user command will be affected (which is exactly the intended design). So plan your USB programs storage carefully, then edit the line below inside the USBProgram user command accordingly.

      :: Change the USB flash drive programs folder below as appropriate.
         Set "USBPrograms={alias|homeroot}PortableApps"

    You must always leave the "{alias|homeroot}" portion and the surrounding quotes shown in the command line above intact. If you were to use the root of your USB flash drive, then you would use only "{alias|homeroot}". Don't worry about each individual program's program folder; USBProgram user command accepts a RELATIVEPATH parameter, which tells it where each program's individual folder is located relative to your main USB programs folder.

    NOTE: For Directory Opus versions below v9.5, use "{alias|home|}" instead of "{alias|homeroot}".

  4. USBProgram expects that a file named "USBFlashDrive.chk" resides in the Opus program folder on your USB Flash Drive. This check file is a safety feature to help ensure that USBProgram only runs programs from Directory Opus running from a USB flash drive. The user command NT Command script will abort by-design from a PC-based Opus installation. It does not matter what the file contains, only that it exists.
  5. The icon used is from the Opus 9 Unofficial Extra Icons, which I have recently updated.


  1. Download the attached .zip file and extract it to a folder.
  2. List the extracted .zip folder in an Opus lister which contains:
    • USBProgram.ouc - USBProgram Directory Opus user command.
  3. Right-click any Opus toolbar and select Customize.
  4. Click on the Customize - Commands Tab.
  5. Click on the User category.
  6. In the Customize dialog's File Menu, select "Import Command...".
  7. When prompted by the "Select Command to Import" file requester, browse to the folder, and open the USBProgram.ouc file.
  8. At this point, the USBProgram user command is imported and should be listed in the User Commands category and selected. Double-click on the USBProgram entry to edit the user command.
  9. In the Directory Opus Command Editor, edit the following code appropriate to your USB flash drive folder structure as discussed earlier.
            :: Change the USB flash drive programs folder below as appropriate.
           Set "USBPrograms={alias|homeroot}PortableApps"</pre></li>
  10. After you have completed your edit, click the OK button in the Directory Opus Command Editor to save your changes and close the editor.
  11. Click the OK button in the Directory Opus Customize dialog.
  12. List the Directory Opus program folder on the USB flash drive that contains the files listed below. (This will be the folder the "home" alias refers to when Directory Opus runs from USB.)
    • d8viewer.exe
    • dopus.exe
    • dopusrt.exe
  13. In this folder, create a text file named USBFlashDrive.chk. It does not matter what this file actually contains, only that it exists.

For a practical application example, check out my Sysinternals Suite Menu running from USB.

I hope you find this useful :smiley: and educational :bulb: (4.12 KB)