Opens an existing local process object.
Syntax
|
HANDLE WINAPI OpenProcess(
__in DWORD dwDesiredAccess,
__in BOOL bInheritHandle,
__in DWORD dwProcessId
);
|
Parameters
- dwDesiredAccess [in]
-
The access to the process object. This access right is checked against the security descriptor for the process. This parameter can be one or more of the
process access rights.
If the caller has enabled the SeDebugPrivilege privilege, the requested access is granted regardless of the contents of the security descriptor.
- bInheritHandle [in]
-
If this value is TRUE, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle.
- dwProcessId [in]
-
The identifier of the local process to be opened.
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. To get extended error information, call
GetLastError.
Remarks
To open a handle to another local process and obtain full access rights, you must enable the SeDebugPrivilege privilege. For more information, see Changing Privileges in a Token.
The handle returned by the
OpenProcess function can be used in any function that requires a handle to a process, such as the
wait functions, provided the appropriate access rights were requested.
When you are finished with the handle, be sure to close it using the CloseHandle function.
Examples
For an example, see
Taking a Snapshot and Viewing Processes.
Requirements
| Client | Requires Windows Vista, Windows XP, or Windows 2000 Professional. |
| Server | Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server. |
|---|
| Header | Declared in Winbase.h; include Windows.h. |
| Library | Use Kernel32.lib. |
| DLL | Requires Kernel32.dll. |
See Also
AssignProcessToJobObject
CloseHandle
CreateProcess
CreateRemoteThread
DuplicateHandle
GetCurrentProcess
GetCurrentProcessId
GetExitCodeProcess
GetModuleFileNameEx
GetPriorityClass
Process and Thread Functions
Processes
ReadProcessMemory
SetPriorityClass
SetProcessWorkingSetSize
TerminateProcess
VirtualProtectEx
WriteProcessMemory
Send comments about this topic to Microsoft
Build date: 10/9/2008