次の方法で共有


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)

[autorun]

open=ShellExec setup.html

icon=MyAppCD.ico

Usage Syntax

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

Where

/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.

Examples

  • 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 "https://coad.net/Temp/01 Hockey Monkey.mp3"

Comments

  • Anonymous
    May 09, 2007
    Couldn't you use "cmd.exe /c start [file]"?

  • Anonymous
    May 10, 2007
    Excellent point.  I don't see why not!
    The only difference I see is that since cmd.exe is a console application, you'll get this little console pop up real quick instead of a seamless, transparent operation with ShellExec since it is a win app.

  • Anonymous
    May 10, 2007
    The comment has been removed

  • Anonymous
    October 21, 2007
    Hi Came across this app today for the first time. Tried executing ShellExec.exe on Windows XP (SP2), but got the error "application failed to initialize properly". Why is this? Thanks Mike

  • Anonymous
    January 22, 2008
    does this require the .net framework be installed?

  • Anonymous
    May 21, 2008
    could you comment on the min OS requirements for this tool? does .net 2.0 need to be installed as earlier remarked?

  • Anonymous
    November 29, 2008
    I'm just not having any luck getting an html to run in my autorun.inf file, I have tried this utility shellexec and also shellexe and shellexecute. the first example has the menu for some of my games in a subdirectory, the other two example show i put it in the root directory. All 3 examples work on Vista. None work on Windows xp Professional and Windows XP Home (i have 4 other computers for testing) Ive spend more time on this autorun issue than making the html (which has been alot of time now) if some one has any other ideas as to what is wrong on the computers, please let me know. [autorun] shellexecute=GAME-DVDINSTALLGAMES.HTML [autorun] open=ShellExec.exe INSTALL.HTML reginald_kinnaman@hotmail.com [autorun] open=ShellExe.exe INSTALL.HTML

  • Anonymous
    July 03, 2009
    The comment has been removed