Process Management
CreateProcessW
+Creates a new process and its primary thread. The new process runs in the same address space of the calling process or in a separate address space.
Syntax
BOOL WINAPI CreateProcessW(
[in, optional] LPCWSTR lpApplicationName,
[in, out, optional] LPWSTR lpCommandLine,
[in, optional] LPSECURITY_ATTRIBUTES lpProcessAttributes,
[in, optional] LPSECURITY_ATTRIBUTES lpThreadAttributes,
[in] BOOL bInheritHandles,
[in] DWORD dwCreationFlags,
[in, optional] LPVOID lpEnvironment,
[in, optional] LPCWSTR lpCurrentDirectory,
[in] LPSTARTUPINFOW lpStartupInfo,
[out] LPPROCESS_INFORMATION lpProcessInformation
);
Parameters
Name | Type | Description |
---|---|---|
lpApplicationName | LPCWSTR |
The name of the module to be executed. |
lpCommandLine | LPWSTR |
The command line string for the process. |
lpProcessAttributes | LPSECURITY_ATTRIBUTES |
Security attributes for the process. |
lpThreadAttributes | LPSECURITY_ATTRIBUTES |
Security attributes for the primary thread. |
bInheritHandles | BOOL |
If TRUE, the child process inherits handles. |
dwCreationFlags | DWORD |
Flags that control the creation of the process. |
lpEnvironment | LPVOID |
Environment block for the new process. |
lpCurrentDirectory | LPCWSTR |
The current directory for the process. |
lpStartupInfo | LPSTARTUPINFOW |
Startup information for the new process. |
lpProcessInformation | LPPROCESS_INFORMATION |
Receives information about the new process. |
Return Value
Returns TRUE if successful, FALSE otherwise. Call GetLastError
for more information.
Remarks
This function is used extensively for launching applications and other processes on Windows.
GetCurrentProcessId
+Retrieves the process identifier of the calling process.
Syntax
DWORD WINAPI GetCurrentProcessId(void);
Return Value
The return value is the process identifier of the calling process.
Remarks
Process identifiers are unique within a system.
TerminateProcess
+Terminates the specified process and any threads that it owns.
Syntax
BOOL WINAPI TerminateProcess(
[in] HANDLE hProcess,
[in] UINT uExitCode
);
Parameters
Name | Type | Description |
---|---|---|
hProcess | HANDLE |
A handle to the process to be terminated. |
uExitCode | UINT |
The application-defined exit code. |
Return Value
Returns TRUE if successful, FALSE otherwise.
Remarks
This function is used to forcefully end a process.
Common Structures
PROCESS_INFORMATION
+Contains information about a newly created process and its primary thread.
Members
Name | Type | Description |
---|---|---|
hProcess | HANDLE |
A handle to the new process. |
hThread | HANDLE |
A handle to the primary thread of the new process. |
dwProcessId | DWORD |
The identifier of the new process. |
dwThreadId | DWORD |
The identifier of the primary thread of the new process. |
STARTUPINFOW
+Specifies the window station, standard handles, and appearance of the main window for a process.
Members
Name | Type | Description |
---|---|---|
cb | DWORD |
The size of the structure, in bytes. |
lpReserved | LPWSTR |
Reserved; must be NULL. |
lpDesktop | LPWSTR |
The name of the desktop. |
lpTitle | LPWSTR |
The title of the window. |
dwX | DWORD |
The x-coordinate of the upper-left corner of the window. |
dwY | DWORD |
The y-coordinate of the upper-left corner of the window. |
dwXSize | DWORD |
The width of the window. |
dwYSize | DWORD |
The height of the window. |
dwXCountChars | DWORD |
The number of characters in the width of the console window. |
dwYCountChars | DWORD |
The number of characters in the height of the console window. |
dwFillAttribute | DWORD |
The background and text colors in the console window. |
dwFlags | DWORD |
Flags that control whether the other members of this structure are used. |
wShowWindow | WORD |
How the window is to be shown. |
cbReserved2 | WORD |
|
hStdInput | HANDLE |
Handle to the standard input buffer. |
hStdOutput | HANDLE |
Handle to the standard output buffer. |
hStdError | HANDLE |
Handle to the standard error buffer. |