
 ShelExec v1.28 An application + source code 
to call the ShellExecute API
ShelExec v1.28 An application + source code 
to call the ShellExecute API
Welcome to ShelExec, A very simple utility to allow you to call the ShellExecute 
API from the command line.
Places where you might find ShelExec useful are in adding an autorun.inf file to 
your CD / DVD +/- RW discs. For example suppose you have a HTML page called index.htm 
on the root of your CD which you would like to run automatically whenever the user 
inserts the CD. All you need to do is put ShelExec.exe, some ico file (this is optional 
as is the icon=... in the autorun.inf file) and the index.htm files into the root 
directory and create a autorun.inf file with the following contents:
[autorun]
open=ShelExec.exe @EXEDRV@\index.html
icon=youricon.ico
Note that it is important to use the @EXEDRV@ or @EXEDIR@ replacement parameters 
as this helps ensures that ShelExec uses a fully quoted path when it runs your program. 
Otherwise you can get some problems on various versions of Windows with your AutoRun 
CD's.
Items that ShelExec can handle include any file which is registered with the shell 
e.g. Word .Doc files, Text Files, batch files etc etc. It can also handle URLS such 
as "http://www.naughter.com",
"ftp://ftp.microsoft.com " 
and "mailto:pjna@naughter.com". 
The more technically minded of you may say why is there a need to have this program 
since you can use "start filename" on autorun CD's without any apparent 
problems. The problem with this approach is that it does not work on NT kernel because 
on these operating systems "start" is implemented as an "Internal" 
command in cmd.exe (as opposed to a standard exe on Windows 9x) with the upshot 
that your CD's will not AutoRun on these operating systems. Using ShelExec will 
mean that your CD's will autorun on all OS's which support it. 
 
The enclosed zip file contains the ShelExec 
source code and a number of prebuilt binaries of ShelExec.
 
Copyright
	- You are allowed to include the source code in any product (commercial, shareware, 
	freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you 
	cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are 
	only allowed to distribute versions released by the author. This is to maintain 
	a single distribution point for the source code.
- The executable file itself, namely "ShelExec.exe" can be freely 
	redistributed by anyone.
 
Updates
v1.28 (14 February 2025)
	- Updated copyright details. 
- Updated CMyCommandLineInfo::ParseParam code to handle "EXE" command line 
	option case insensitively. Thanks to Tomáš Volko for reporting this issue.
- Updated GetModuleFileName calls to handle path length > _MAX_PATH.
- Reworked CShelExecApp::InitInstance to use std::filesystem::path.
v1.27 (26 May 2022)
	- Updated copyright details. 
- Updated the code to use C++ uniform initialization for all variable 
	declarations.
v1.26 (5 April 2020)
	- Updated copyright details. 
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.25 (23 December 2019)
	- Fixed various Clang-Tidy static code analysis warnings in the code.
v1.24 (1 June 2019)
	- Updated copyright details.
- Updated the code to clean compile on VC 2019
v1.23 (2 October 2018)
	- Updated copyright details.
- Fixed a number of C++ core guidelines compiler warnings. These changes 
	mean that the code will now only compile on VC 2017 or later.
v1.22 (27 December 2017)
	- Updated copyright details.
- Replaced CString::operator LPC*STR() calls throughout the codebase 
	with CString::GetString calls 
- Replaced NULL throughout the codebase with nullptr. This means that the 
	minimum requirement for the code is now VC 2010. 
v1.21 (23 October 2016)
	- Updated the app to allow it to build as both a GUI based application and 
	now as a console based application. The console based version provides better 
	usage when used from command line scripts etc. Thanks to "LinuxKungFu" 
	for prompting this update.
v1.20 (31 July 2016)
	- Updated copyright details.
- Remove the TIMEOUT command line parameter and the hidden window which gets 
	created by ShelExec.
- Fixed a resource leak where the code would not release the hProcess handle 
	which can be returned from ShellExecuteEx.
- The application now sets the ShelExec process return code based on any error 
	values which occur while being run.
- Calling the GetShortPathName API to convert from a long filename to a 8.3 
	filename is now completely based on the "NOSFNC" command line option.
- Reworked the IDP_USAGE messagebox text.
- Tidied up the implementation of the CMyCommandLineInfo::ParseParam method.
- Introduced a new /NOUI command line option.
- Improved the error message displayed when GetModuleFileName API fails.
- Introduced a new /WAITFORINPUTIDLE command line option.
- Introduced a new /MONITOR command line option.
v1.19 (25 July 2015)
	- Updated copyright details.
- Updated the project settings to more modern defaults.
- Updated the code to clean compile on VC 2013 & VC 2015.
- The download now includes a number of precompiled binaries of ShelExec.exe. 
	In the Release directory is an ASCII x86 build, while in the ReleaseU directory 
	is a Unicode x86 build while the ReleaseU64 directory includes a Unicode x64 
	build. Thanks to Andrew Leonard for prompting this update.
16 April 2013
	- Minor update to the app to refer to the /NOSFNC command line option when 
	it is run with no command line.
v1.18 (14 April 2013)
	- Updated copyright details.
- Updated the code to compile cleanly on VC 2010 and later using /analyze.
- Following a request from Thorsten Schöning, ShelExec now includes support 
	for a new /NOSFNC command line option. If this is specified, then the program 
	will pass the long filename down to the Win32 ShellExecute API. If this command 
	line option is not set (which is the default), then the program will continue 
	to pass the 8.3 short filename to the API.
v1.17 (12 January 2008)
	- Updated copyright details.
- Removed VC 6 style classwizard comments.
- Code now uses the FORMAT_MESSAGE_IGNORE_INSERTS flag when calling FormatMessage. 
	For more information please see Raymond Chen's blog at
	
	http://blogs.msdn.com/oldnewthing/archive/2007/11/28/6564257.aspx. Thanks 
	to Alexey Kuznetsov for reporting this issue.
- App now supports environment variable substitution in the Dir and DocumentFile 
	parameters.
- App now no longer passes GetDesktopWindow() for the parent window in the 
	call to ShellExecuteEx.
- App now no longer bothers reporting any errors back since the ShellExecuteEx 
	call is doing this for us anyway because we are not passing the SEE_MASK_FLAG_NO_UI 
	flag.
- The app now no longer creates the hidden window if the call to ShellExecuteEx 
	was unsuccessful.
v1.16 (21 December 2006)
	- Updated copyright details.
- ShelExec is now built with VC 2005 SP1.
- Updated documentation to use the same style as the web site.
- Code now uses newer C++ style casts instead of C style casts.
v1.15 (23 September 2005)
	- Documentation has been updated to show how you should use fully quoted paths 
	if using ShelExec to create AutoRun applications. Thanks to newsgroup feedback 
	and John McCoy for reporting this issue.
- ShelExec now reports the fleshed out error description by using the FormatMessage 
	API.
3 July 2004
	- Now includes explicit info on the usage of the executable "ShelExec.exe" 
	in the documentation
v1.14 (24 January 2003)
	- Now provides a /WAIT command line parameter. This allows the ShelExec application 
	to only return when the application it starts has exited. Thanks to Igor Rabinovich 
	for this suggestion.
v1.13 (18 October 2002)
	- Changed the format of replacable parameters from using a "%" to 
	now use a "@". This is to avoid problems with replaceable environment 
	parameters in the OS. Thanks to Ted Tsoutsas for reporting this problem. This 
	means that the previous example in the v1.12 notes should now be used as:
 
 ShelExec.exe "/PARAMS:/play @EXEDRV@\data\myfile.xyz" /EXE @EXEDIR@\Prog\MyProg.exe
 
- Added a new replaceable parameter "@QUOTE" which puts a Quote 
	character i.e. " into the string when the program is called. For example 
	to call Notepad with the file "c:\A directory with spaces\file.txt" 
	and ensure that the filename is embedded with quotes, you would use the following 
	command line:
 
 ShelExec.exe "/PARAMS:@QUOTE@c:\directory with spaces\file.txt@QUOTE@" 
	/EXE notepad.exe
v1.12 (17 October 2002)
	- ShelExec is now compiled with Visual C++ 6 instead of Visual C++ 5.
- Removed an unreferrenced variable in CShelExecApp::InitInstance.
- Program now supports two parameters in the "/DIR", "/PARAMS" 
	and filename command line values. These are: %EXEDRV% which gets replaced with 
	the drive letter path where AutoPlay is run from. the other variable is %EXEDIR%. 
	For example:
 
 ShelExec.exe "/PARAMS:/play %EXEDRV%\data\myfile.xyz" 
	/EXE %EXEDIR%\Prog\MyProg.exe
 
 What this command line would achieve is 
	to run a program called MyProg.exe located in the "D:\Prog" directory 
	on the root of your CD (assuming your CD drive is D:) using the command line "/play 
	D:\data\myfile.xyz".
 
 Thanks to Ted Tsoutsas for this nice 
	update.
29 July 2002
	- Updated documentation which comes with ShelExec to explain how to work with 
	filenames which contain embedded spaces.
v1.11 (1 October 2001)
	- Fixed a bug which was causing ShelExec to fail on some versions of Windows 
	with the error code 1155.
- Updated version infos of the exectuable.
- Code now uses ShellExecuteEx instead of ShellExecute internally.
- A hidden window is now created when ShelExec starts. This allows verbs such 
	as "properties" to now work correctly. Thanks to Santosh Rao for suggesting 
	this addition.
- Icon used for ShellExec is now consistent with the new icon styles used 
	by Windows XP.
v1.1 (10 February 2001)
	- Program now understands a /EXE command line which allows the a specific 
	command line to be specified: e.g ShelExec.exe /EXE mplayer2.exe "/PARAMS:/play 
	E:\WINNT\Media\canyon.mid".
- Program now understands a /DIR:Value command line which allows the startup 
	directory for an application to be specified.
- Updated copyright information.
10 November 2000 
	- Updated distribution to include missing files.
v1.02 (9 April 2000) 
	- Fixed a bug where the verb "Open" was always used.
- Program now understands a /Verb:Value command line which allows the verb 
	to be specified as used in the ShellExecute call. Not specifying a verb will 
	use the default value for the file as setup in the registry.
- Program now understands a /ShowCmd:Value command line which allows the
	"nShowCmd" value to be specified as used in the ShellExecute 
	call. Not specifying a value will use the value SW_SHOW.
- Code now uses MFC internally.
- Code now supports UNICODE and build configurations are provided
v1.01 (16 July 1999)