ShellExecuteW Function
The ShellExecuteW function performs an operation on a specified file.
Syntax
BOOL ShellExecuteW(
HWND hwnd,
LPCWSTR lpOperation,
LPCWSTR lpFile,
LPCWSTR lpParameters,
LPCWSTR lpDirectory,
INT nShowCmd
);
Parameters
-
hwnd
HWND
A handle to the window that is to be the owner of any dialog boxes that appear. If this parameter is NULL, the function will not display any dialog boxes. -
lpOperation
LPCWSTR
A pointer to a null-terminated string that specifies the action to be performed. This parameter can be NULL, in which case the default action is performed. The actions are defined by the verb associated with the file object, which is stored in the registry.Common verbs include:
NULL(default action)openeditprintexploreproperties
-
lpFile
LPCWSTR
A pointer to a null-terminated string that specifies the file or object on which to perform the action. -
lpParameters
LPCWSTR
A pointer to a null-terminated string that specifies the parameters to be passed to the application being executed. This parameter can be NULL. -
lpDirectory
LPCWSTR
A pointer to a null-terminated string that specifies the default directory for the application. This parameter can be NULL. -
nShowCmd
INT
The way the application window is to be shown. SeeShowWindowfor a list of the possible values.
Return Value
If the function succeeds, it returns a value greater than 32. If the function fails, it returns a value less than or equal to 32. Common errors include:
ERROR_FILE_NOT_FOUND(2)ERROR_PATH_NOT_FOUND(3)ERROR_BAD_FORMAT(11)SE_ERR_ACCESSDENIED(5)SE_ERR_ASSOCINCOMPLETE(27)SE_ERR_DDETIMEOUT(28)SE_ERR_DLLNOTFOUND(32)SE_ERR_NOASSOC(31)SE_ERR_OOM(8)SE_ERR_SHARE(26)
You can use the GetLastError function to get extended error information.
Remarks
ShellExecuteW is the wide-character (Unicode) version of ShellExecute.
When you pass NULL for lpOperation, ShellExecuteW performs the default action for the specified file. The default action is determined by the file's extension and its association in the registry.
To execute a file that is not an executable file (such as a document), you can use ShellExecuteW to open it with its associated application.
If lpFile specifies a file and lpOperation is NULL or "open", the system uses the default verb associated with the file type.
If the file is an executable file, you can specify the operation as "runas" to run the executable with administrative privileges. If the user has not granted administrator privileges, the system displays a UAC prompt.