WinExec function (winbase.h)
Runs the specified application.
UINT WinExec( LPCSTR lpCmdLine, UINT uCmdShow );
The command line (file name plus optional parameters) for the application to be executed. If the name of the executable file in the lpCmdLine parameter does not contain a directory path, the system searches for the executable file in this sequence:
- The directory from which the application loaded.
- The current directory.
- The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
- The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
- The directories listed in the PATH environment variable.
The display options. For a list of the acceptable values, see the description of the nCmdShow parameter of the ShowWindow function.
If the function succeeds, the return value is greater than 31.
If the function fails, the return value is one of the following error values.
||The system is out of memory or resources.|
||The .exe file is invalid.|
||The specified file was not found.|
||The specified path was not found.|
The WinExec function returns when the started process calls the GetMessage function or a time-out limit is reached. To avoid waiting for the time out delay, call the GetMessage function as soon as possible in any process started by a call to WinExec.
WinExec("C:\\Program Files\\MyApp", ...)
If a malicious user were to create an application called "Program.exe" on a system, any program that incorrectly calls WinExec using the Program Files directory will run this application instead of the intended application.
To avoid this problem, use CreateProcess rather than WinExec. However, if you must use WinExec for legacy reasons, make sure the application name is enclosed in quotation marks as shown in the example below.
WinExec("\"C:\\Program Files\\MyApp.exe\" -L -S", ...)
|Minimum supported client||Windows XP [desktop apps only]|
|Minimum supported server||Windows Server 2003 [desktop apps only]|
|Header||winbase.h (include Windows.h)|
|API set||ext-ms-win-kernel32-process-l1-1-0 (introduced in Windows 10, version 10.0.14393)|