OpenProcess () function

Source: Internet
Author: User

method Name: OpenProcessLocation: Kernel32.dllThe openprocess function is used to open an existing process object and return a handle to the process. 1. Function PrototypesHANDLE OpenProcess (DWORD dwDesiredAccess,BOOL bInheritHandle,DWORD Dwprocessid); 2. Parameters A. dwDesiredAccess:The process access permissions you want to haveprocess_all_access//All available permissionsprocess_create_process//need to create a processProcess_create_thread//need to create a threadProcess_dup_handle//re-use DuplicateHandle handleprocess_query_information//Get permission to process information, such as its exit code, priorityprocess_query_limited_information/* Access to certain information, if Process_query_information is obtained, also hasprocess_query_limited_information the same permissionsprocess_set_information//permission to set certain information, such as process priorityProcess_set_quota//Set memory limit permissions, use SetProcessWorkingSetSizeProcess_suspend_resume//suspend or resume a process's permissionsprocess_terminate//Terminate permissions on a process, using terminateprocessProcess_vm_operation//operating process memory space permissions (available Virtualprotectex and writeprocessmemory)Process_vm_read//Read the permissions of the process memory space, you can use ReadProcessMemoryprocess_vm_write//Read the permissions of the process memory space, you can use WriteProcessMemorySYNCHRONIZE//wait for process to terminate B. bInheritHandle: Indicates whether the resulting process handle can be inheritedc. DWPROCESSID: PID of the Open process

3. Return type

If successful, the return value is a handle to the specified process. Integer or Intptr

If it fails, the return value is NULL, and you can call GetLastError () to get the error code.

When you close another process through a process, it is common practice to enumerate the identifier (PID) of the process being opened by the system, and use the OpenProcess function to get a handle to the process, which can set the new access permission for the handle by the first parameter (it is unclear if the handle is the same as the original). To be proved and learned), for example, if the open handle does not have permission to terminate the handle, the line terminate process operation fails with an error code of 5 (meaning Deny access). By obtaining a handle you can get the process name (via the GetModuleBaseName function), and we can get the process we specified to close by the name of the process. Note: To use the CloseHandle function to reduce the process counter.

This document was reproduced in: http://blog.csdn.net/pxm2525/article/details/39828815

OpenProcess () function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.