CreateProcess Function
This topic describes the CreateProcess
function, which creates a new process and its primary thread. The new process runs in the security context of the calling process.
_In_opt_ const char *lpApplicationName,
_Inout_opt_ char *lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ const void *lpEnvironment,
_In_opt_ const char *lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
Parameters
Parameter | Type | Description |
---|---|---|
lpApplicationName |
const char * |
The name of the module to be executed. The string must be a full path. If this parameter is NULL, the module name is taken from the first token in the lpCommandLine string. |
lpCommandLine |
char * |
The command line string for the new process. The length of this string is limited to 32K characters. If lpApplicationName is NULL, the first character of this string must be the executable name. |
lpProcessAttributes |
LPSECURITY_ATTRIBUTES |
A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If NULL, the handle cannot be inherited. |
lpThreadAttributes |
LPSECURITY_ATTRIBUTES |
A pointer to a SECURITY_ATTRIBUTES structure that specifies the security descriptor for the primary thread of the new process. If NULL, the thread is assign the same security attribute as the process. |
bInheritHandles |
BOOL |
Specifies whether the new process inherits the calling process's handles. |
dwCreationFlags |
DWORD |
Flags that control the priority class and behavior of the new process. For example, CREATE_NEW_CONSOLE , DETACHED_PROCESS , HIGH_PRIORITY_CLASS . |
lpEnvironment |
const void * |
A pointer to a null-terminated list of strings, which represents the environment for the new process. If NULL, the new process inherits the environment of the calling process. |
lpCurrentDirectory |
const char * |
A pointer to a null-terminated string that specifies the full path of the current directory for the process. |
lpStartupInfo |
LPSTARTUPINFO |
A pointer to a STARTUPINFO structure that specifies the window station, standard handles, and appearance of the main window for the new process. |
lpProcessInformation |
LPPROCESS_INFORMATION |
A pointer to a PROCESS_INFORMATION structure that receives information about the new process, including its handle and identifier. |
Return Value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError
.
Remarks
The CreateProcess
function creates a new process that begins execution at the creation function of the specified executable program. The new process gets its own memory address space, but it is created within the context of the calling process.
If lpApplicationName
is NULL, the function uses the executable name from lpCommandLine
. If the executable name is not found, the system searches for it in the following order:
- The directory of the current executable.
- The system directory.
- The Windows directory.
- The directories listed in the PATH environment variable.
- The current directory.
CreateProcessW
, as it is the preferred method for developing new applications.
To create a detached process that does not inherit handles from the parent process, use the DETACHED_PROCESS
flag in dwCreationFlags
.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows 2000 Professional |
Minimum supported server | Windows 2000 Server |
Header | Process.h |
Library | Kernel32.lib |
DLL | Kernel32.dll |