shexec

execute Windows operation on an application, document, or folder 

Command


SYNOPSIS

shexec [-qwZ?] [-a args] [-d directory] [-p handle] [-s minimized|maximized|hidden|normal] [-v action] file


DESCRIPTION

The shexec utility executes the specified application or document (file) and performs the specified action (see the description of -v in the Options section) on file. file can be an application, document, or folder. A document, in this case, is any file associated with a specific application. For example, URLs are associated with your browser, so a URL is a document. Other documents would include Microsoft Word files, Microsoft Excel spreadsheets, movie files associated with the Windows Media Player (or other video player), and so forth.

When the -v option is not specified, the default action (also called a verb), as specified in the registry, is used if available. When the default action is not available, the open action is used. On 8.1/2012R2/2016/2019/2022 systems, when neither the default action or open is available, the system uses the first verb listed in the registry.

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 8.1/2012R2/2016/2019/2022 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 -? option). This approach lets you use shexec in situations (such as CD autoruns) where having a console window pop up would be annoying or impractical.

Options

-a args 

specifies the application arguments to be used when file is executed. This option is only valid when file is an application.

-d directory 

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, .).

-p handle 

specifies the handle of a parent window which is to be used for error reporting.

-q 

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 normal mode.

Note:

While shexec always passes this argument to the application, some applications ignore it.

-v action 

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:

edit 

launches an editor and opens the file for editing. This action is only valid when file is a document.

explore 

launches Windows Explorer with the folder specified by file open. This action is only valid when file is a folder.

find 

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.

open 

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.

print 

prints the document specified by file using the application associated with that document. This action is only valid when file is a document.

runas 

on Windows 8.1/2012R2/10/2016/2019/11/2022, runs file unrestricted by User Access Protection. This is recommended primarily for running a shell, command interpreter, or other interacive program.

-w 

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.

Note:

Not all shexec commands launch new processes (for example, Windows Explorer and Microsoft Word use DDE transactions).

-Z 

do not perform zone checking as found in Windows XP Service Pack 1 and later.

-? 

displays help information in a pop-up dialog.


EXAMPLES

The following command launches Windows Explorer with the current directory open:

shexec .

This command launches the system's default browser open to the MKS Web site:

shexec http://www.mks.com

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


DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

1 

Incorrect arguments were specified or the operating system is out of memory or resources.

>1 

An error occurred.

Note:

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.


PORTABILITY

Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.


AVAILABILITY

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


LICENSE

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 tk_info@mkssoftware.com).

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.4 Documentation Build 39.