ShellExec (a tiny tool)

Download ShellExec (source code)

Here's a really simple but surprisingly useful little tool.  It performs a shell execution of a command.  That's it.  Some applications only allow you to specify an executable to run as opposed to a file or URL.  This is because they spin up a new process from the executable instead of using the shell to execute the command.  This tool bridges the gap.  You can call it as an executable and it runs the command line arguments as a shell command.

Start-Run vs cmd.exe

When running something from Start -> Run (Win-R key) a shell execution is performed, so links or files open fine.  cmd.exe does not use shell execution, so if you wanted to open a file or URL from the command line, you'd have to know the application assigned to handle the file/URL, or use a shell execution (like ShellExec myfile.txt)  BTW, 4NT does perform shell executions at the command line.

CD Autorun Example

Another example is the autorun.ini file for a CD.  Say you want to launch a .hta, .html, .txt, or URL?  You can't directly because an executable is required.  Here's a sample Autorun.ini that opens Setup.html when the CD is inserted (assuming ShellExec.exe is in the root directory w/ setup.html)


open=ShellExec setup.html


Usage Syntax

ShellExec [/ec|/ea] <cmd> [<args>]
ShellExec /c
ShellExec /?
ShellExec /about


/ec Expand environment variables on the command only
/ea Expand environment variables on the entire line (command and arguments)
<cmd>  The command to be run with the shell
<args>   Arguments to be passed to the command
/? Show the usage syntax
/c Run what's in the clipboard.
/about Show this web page.


  • Want to launch a file using the shell's associated application?
    ShellExec MoreInfo.txt
  • Need environment variable expansion in an app that doesn't support it?
    ShellExec /ec "%windir%\notepad.exe"
  • How about running a URL?
    ShellExec " Hockey Monkey.mp3"