How to obtain Process Handle

Source: Internet
Author: User
After a process is created using CreateProcess, The PROCESS_INFORMATION structure will contain the handle of the process and a unique process ID. Then, when you use openprocess to open the process, according to the first parameter (dwDesiredAccess: PROCESS_ALL_ACCESS all the permissions that can be obtained by this process

After a process is created using CreateProcess, The PROCESS_INFORMATION structure will contain the handle of the process and a unique process ID. Then, when you use openprocess to open the process, according to the first parameter (dwDesiredAccess: you want to have the process access permission PROCESS_ALL_ACCESS // all the obtained permissions PROCES

Use CreateProcess to createProcessThe PROCESS_INFORMATION structure containsProcessHandle, and uniqueProcessID

Use openprocess to openProcessAccording to the first parameter

(DwDesiredAccess:ProcessAccess permission
PROCESS_ALL_ACCESS // all permissions that can be obtained
PROCESS_CREATE_PROCESS // you need to createProcess
PROCESS_CREATE_THREAD // you need to create a thread.
PROCESS_DUP_HANDLE // reuse DuplicateHandle handle
PROCESS_QUERY_INFORMATION // obtainProcessInformation permissions, such as its exit code and priority
PROCESS_QUERY_LIMITED_INFORMATION/* obtain certain information. If PROCESS_QUERY_INFORMATION is obtained, PROCESS_QUERY_LIMITED_INFORMATION is also granted */
PROCESS_SET_INFORMATION // set the permission for certain information, suchProcessPriority
PROCESS_SET_QUOTA // set the memory limit permission and use SetProcessWorkingSetSize
PROCESS_SUSPEND_RESUME // pause or resumeProcessPermissions
PROCESS_TERMINATE // terminateProcessUse TerminateProcess
PROCESS_VM_OPERATION // operationProcessMemory space permission (VirtualProtectEx and WriteProcessMemory are available)
PROCESS_VM_READ // readProcessThe permission for memory space. You can use ReadProcessMemory.
PROCESS_VM_WRITE // readProcessMemory space permission. WriteProcessMemory can be used.
SYNCHRONIZE // waitProcessTermination

)

Different, the returned handle value is different, and is definitely not equal to the handle value in PROCESS_INFORMATION

OpenProcess is used when the program is not closed.ObtainSameProcess, Each time you get a different handle Value

The handle returned by OpenProcess is the temporary operation handle assigned by the system. When CloseHandle (hand) is not used to close the handle, call OpenProcess againObtainA new handle is assigned to you. It is equivalent to the sameProcess

Essentially,ProcessHandle "is not actually trueProcessHandle,ProcessThe index (offset) of the handle in the "handle table ".ProcessThe handle is stored inProcessHandle table

If CloseHandle is disabled after each handle is used, OpenProcessObtainSameProcessYou can get the same handle value.

EachProcessAll have handle tables. The first entry of the table isProcessYour own handle, which is why calling GetCurrentProcess () always returns 0x7FFFFFFF.


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.