MSDN Documentation – Windows API

Process Management API Reference

Key Functions

FunctionHeaderDescription
CreateProcessWindows.hCreates a new process and its primary thread.
OpenProcessWindows.hOpens an existing process object.
TerminateProcessWindows.hEnds the specified process.
GetCurrentProcessWindows.hRetrieves a pseudo handle for the current process.
GetProcessIdProcessthreadsapi.hReturns the process identifier of a process handle.
EnumProcessesPsapi.hEnumerates all process identifiers currently running.
GetProcessTimesWindows.hRetrieves timing information for a process.

Example: Creating a Process

#include <windows.h>
#include <stdio.h>

int main(void) {
    STARTUPINFO si = {0};
    PROCESS_INFORMATION pi = {0};
    si.cb = sizeof(si);

    // Command line to execute
    wchar_t cmdLine[] = L"notepad.exe";

    // Create the new process
    if (!CreateProcessW(
            NULL,          // Application name
            cmdLine,       // Command line
            NULL,          // Process security attributes
            NULL,          // Primary thread security attributes
            FALSE,         // Inherit handles
            0,             // Creation flags
            NULL,          // Environment
            NULL,          // Current directory
            &si,           // STARTUPINFO pointer
            &pi)) {        // PROCESS_INFORMATION pointer
        wprintf(L"CreateProcess failed (error %lu)\\n", GetLastError());
        return 1;
    }

    wprintf(L"Process ID: %lu\\n", pi.dwProcessId);
    // Wait for the created process to exit
    WaitForSingleObject(pi.hProcess, INFINITE);

    // Cleanup
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
    return 0;
}

Related Topics