The shexec utility executes the specified
application or document (file) and performs the specified
action (see the description of
Path names for shexec may be specified in either MKS Toolkit format (for example, c:/) or NuTCRACKER Platform format (for example, /c=/).
This utility has full Unicode support on 7/2008R2/8/2012/2016 systems.
Unlike most MKS Toolkit utilities which are console applications (that is, they
communicate with the user through a console), shexec
is Windows subsystem application and creates its own Windows for user
interaction (for example, the popup dialog displayed by the
specifies the application arguments to be used when file is executed. This option is only valid when file is an application.
specifies the directory in which file is to be executed. When this option is not specified, shexec executes the application or document in the current directory (that is, .).
specifies the handle of a parent window which is to be used for error reporting.
suppresses the display of all error dialogs.
-s minimized| maximized| hidden| normal
specifies to an application how its Window should be displayed when it starts. If file is a document, this information is passed on to the application associated with that document. When this option is not specified, shexec uses
While shexec always passes this argument to the application, some applications ignore it.
specifies the action to be performed upon the specified application or document. The action argument can be any action defined in the registry for the application (either specified directly or indirectly, as the application associated with a document). Here are some of the common actions defined for many applications:
launches an editor and opens the file for editing. This action is only valid when file is a document.
launches Windows Explorer with the folder specified by file open. This action is only valid when file is a folder.
launches the Windows Search with the folder specified by file as the default search location. This action is only valid when file is a folder.
opens file. When file is an application, that application is executed. When file is a document, shexec launches the application associated with file and loads file. When file is a folder, that folder is opened for exploring.
prints the document specified by file using the application associated with that document. This action is only valid when file is a document.
on Windows 7/2008R2/8/2012/10/2016, runs file unrestricted by User Access Protection. This is recommended primarily for running a shell, command interpreter, or other interacive program.
waits for the process to complete (if possible). When a new executable is launched by shexec, shexec waits for that process to complete before continuing.
Not all shexec commands launch new processes (for example, Windows Explorer and Microsoft Word use DDE transactions).
do not perform zone checking as found in Windows XP Service Pack 1 and later.
displays help information in a pop-up dialog.
The following command launches Windows Explorer with the current directory open:
This command launches the system's default browser open to the MKS Web site:
Because no action was explicitly specified, the default open action was used.
Assuming that the .doc extension is associated with Microsoft Word, the following command prints the file c:/docs/word.doc using Word's default print settings.
shexec -v print c:/docs/word.doc
Again, assuming that the .txt extension is associated with Notepad, the following command launches that application with the file c:/docs/notepad.txt open for editing.
shexec -v edit c:/docs/notepad.txt
This command launches Windows Explorer with the folder c:/docs open.
shexec -v explore c:/docs
This next command launches the Windows Search dialog with c:/docs set as the default search directory.
shexec -v find c:/docs
One convenient use of this utility is its ability to let you execute URLs from autorun menus on CD. For example, here is the autorun.inf from an MKS AlertCentre CD:
[AutoRun] open = shexec -v open enter.html icon = AlertCentreInfo-4.ico,0 shell\1_ac = MKS &AlertCentre Home Page shell\1_ac\command = shexec -v open http://www.alertcentre.com shell\2_ac = Request MKS &AlertCentre Evaluation shell\2_ac\command = shexec -v open http://www.mkssoftware.com/eval/evalform.asp?product=alertcentre&distrib=MKS
For this work, you simply need to place shexec.exe (and in this case, enter.html too) in the root directory of the CD. Fortunately, the license for this utility allows you to do that for personal and non-commercial use (see the LICENSE section below).
Possible exit status values are:
Incorrect arguments were specified or the operating system is out of memory or resources.
An error occurred.
Normally, when you run the shexec utility from cmd.exe, the Windows environment variable %ERRORLEVEL% is not set because cmd.exe does not wait for Windows subsystem applications. However, you can work around this, if necessary, by using the following in place of just shexec:
start /wait full_shexec_path
where full_shexec_path is the full path for the shexec utility (for example, c:/program files/mks toolkit/mksnt/shexec.exe).
The MKS KornShell (sh), on the other hand does wait and so $? is set correctly when shexec is run from that shell.
Windows 7. Windows Server 2008 R2. Windows 8. Windows Server 2012. Windows 10. Windows Server 2016.
The shexec utility currently works on on 32-bit Windows systems.
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
This software is offered "as is" and is free and redistributable for personal and non-commercial use only. For use in a commercial/educational/governmental environment or to purchase a registered and supported copy of shexec or to purchase a license to redistribute this software please contact MKS directly (www.mkssoftware.com or firstname.lastname@example.org).
Though this software will work on its own, it was designed and built to work within the MKS Toolkit environment. Find out more about MKS Toolkit products from www.mkssoftware.com.
PTC MKS Toolkit 10.1 Documentation Build 15.