Process Management Functions
This section provides documentation for Windows API functions related to the creation, manipulation, and termination of processes.
CreateProcess
Creates a new process and its primary thread. The new process is represented by a process handle and has its own virtual address space.
Syntax
BOOL CreateProcess( LPCTSTR lpApplicationName, LPTSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCTSTR lpCurrentDirectory, LPSTARTUPINFO lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation );
Parameters
| Parameter | Description |
|---|---|
lpApplicationName |
The name of the module to be executed. |
lpCommandLine |
The command line for the process. |
lpProcessAttributes |
Security attributes for the process. |
lpThreadAttributes |
Security attributes for the primary thread. |
bInheritHandles |
Indicates whether the new process inherits handles. |
dwCreationFlags |
Flags that control the priority class and behavior of the new process. |
lpEnvironment |
The environment block for the new process. |
lpCurrentDirectory |
The fully qualified path for the current directory. |
lpStartupInfo |
A pointer to a STARTUPINFO structure that specifies the window station, standard handles, and appearance of the main window. |
lpProcessInformation |
A pointer to a PROCESS_INFORMATION structure that receives identification information about the new process and its primary thread. |
Return Value
TRUE |
If the function succeeds, the return value is nonzero. |
FALSE |
If the function fails, the return value is zero. |
To get extended error information, call
GetLastError.
ExitProcess
Terminates the calling process and all of its threads. The calling process's exit status is returned to the calling process's parent process.
Syntax
VOID ExitProcess( UINT uExitCode );
Parameters
| Parameter | Description |
|---|---|
uExitCode |
The status code returned to the parent process. |
Calling
ExitProcess does not perform any stack-based cleanup.
TerminateProcess
Specifies an exit status for the specified process and initiates its termination. The calling process must have the appropriate access to the target process.
Syntax
BOOL TerminateProcess( HANDLE hProcess, UINT uExitCode );
Parameters
| Parameter | Description |
|---|---|
hProcess |
A handle to the process to be terminated. |
uExitCode |
The status code returned to the parent process. |
Return Value
TRUE |
If the function succeeds, the return value is nonzero. |
FALSE |
If the function fails, the return value is zero. |
GetProcessId
Retrieves the identifier of the process associated with the specified handle.
Syntax
DWORD GetProcessId( HANDLE Process );
Parameters
| Parameter | Description |
|---|---|
Process |
A handle to the process. |
Return Value
| The process identifier. | If the function succeeds. |
| 0 | If the function fails. To get extended error information, call GetLastError. |