Win32 Processes API Reference

This document provides detailed information on the Win32 API functions related to process management in Windows. Processes are fundamental units of execution within the operating system.

Core Concepts

A process is an instance of a running program. It comprises:

Key Functions

Process Creation

CreateProcess

Creates a new process and its primary thread. The new process runs in the same 32-bit or 64-bit virtual address space as the calling process.

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);

Return Value: Nonzero if the function succeeds, zero otherwise. Call GetLastError for more information.

Parameters:

  • lpApplicationName: Name of the module to be executed.
  • lpCommandLine: Command line string.
  • lpProcessAttributes: Security attributes for the process.
  • lpThreadAttributes: Security attributes for the primary thread.
  • bInheritHandles: Whether the new process inherits handles.
  • dwCreationFlags: Flags that control the priority class and the way the application is displayed.
  • lpEnvironment: Environment block for the new process.
  • lpCurrentDirectory: Current directory for the process.
  • lpStartupInfo: STARTUPINFO structure specifying window and console properties.
  • lpProcessInformation: PROCESS_INFORMATION structure that receives identification.

Learn more about CreateProcess

Process Information

GetCurrentProcess

Returns a pseudo-handle for the current process. A pseudo-handle is a special constant that is equal to the actual handle of the process in which it is embedded.

Syntax: HANDLE GetCurrentProcess(void);

Return Value: The return value is a pseudo-handle for the current process.

Learn more about GetCurrentProcess

GetCurrentProcessId

Returns the process identifier of the calling process.

Syntax: DWORD GetCurrentProcessId(void);

Return Value: The return value is the process identifier of the calling process.

Learn more about GetCurrentProcessId

Process Termination

ExitProcess

Terminates the calling process and all of its threads.

Syntax: VOID ExitProcess(_In_ UINT uExitCode);

Return Value: This function does not return.

Learn more about ExitProcess

Process Management

OpenProcess

Gets a handle to an existing local process object. This handle can be used to specify the process in calls to the process-manipulation functions.

Syntax: HANDLE OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId);

Return Value: If the function succeeds, the return value is an open handle to the specified process. If the function fails, the return value is NULL.

Learn more about OpenProcess

TerminateProcess

Marks a process and all of its threads for termination. The calling process must have the appropriate access rights to the target process.

Syntax: BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode);

Return Value: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.

Learn more about TerminateProcess

Process Security and Access Rights

Processes have security descriptors that control access. Common access rights include:

Note: Ensure you request only the necessary access rights to adhere to the principle of least privilege.

Related Topics