Win32 apps

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

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.

See Also