Right to get the process path and get a list of processes

Source: Internet
Author: User

1, the process to raise the right:

  1. BOOL Cprogressinfo::adjustprivileges ()
  2. {
  3. HANDLE htoken = NULL;
  4. token_privileges TP = {0};
  5. Token_privileges OLDTP = {0};
  6. DWORD dwsize = sizeof (token_privileges);
  7. LUID LUID = {0};
  8. if (! OpenProcessToken (GetCurrentProcess (), Token_adjust_privileges | Token_query, &htoken)) {
  9. if (GetLastError () ==error_call_not_implemented)
  10. return TRUE;
  11. Else
  12. return FALSE;
  13. }
  14. if (! Lookupprivilegevalue (NULL, Se_debug_name, &luid)) {
  15. CloseHandle (Htoken);
  16. return FALSE;
  17. }
  18. Tp. Privilegecount=1;
  19. Tp. Privileges[0]. Luid = Luid;
  20. Tp. Privileges[0]. Attributes = se_privilege_enabled;
  21. / * Adjust Token privileges * /
  22. if (! AdjustTokenPrivileges (Htoken, FALSE, &TP, sizeof (token_privileges), &OLDTP, &dwsize)) {
  23. CloseHandle (Htoken);
  24. return FALSE;
  25. }
  26. //Close handles
  27. CloseHandle (Htoken);
  28. return TRUE;
  29. }

2. Get the process list (you can get the basic process path after the right):

  1. BOOL cprogressinfo::getprogresslist ()
  2. {
  3. BOOL bresult = FALSE;
  4. HANDLE hsnap = createtoolhelp32snapshot (th32cs_snapprocess, 0);
  5. if (Hsnap = = Invalid_handle_value)
  6. return FALSE;
  7. HANDLE hprocess = NULL;
  8. PROCESSENTRY32 info = {0};
  9. Info.dwsize = sizeof (PROCESSENTRY32);
  10. BOOL bRet = Process32First (Hsnap, &info);
  11. While (BRet) {
  12. hprocess = OpenProcess (process_query_information | Process_vm_read, FALSE, Info.th32processid);
  13. if (hprocess) {
  14. Getmodulefilenameex (hprocess, NULL,/ * buffer pointer */, MAX_PATH); Get process Path
  15. }
  16. BRet = Process32Next (Hsnap, &info);
  17. }
  18. return TRUE;
  19. }

3, according to the process of PID, to end this process:

  1. void Cprogressinfo::D eleteprogress (DWORD PUID)
  2. {
  3. HANDLE Hprocesshandle;
  4. Hprocesshandle =:: OpenProcess (Process_terminate, False,puid);
  5. if (hprocesshandle)
  6. {
  7. TerminateProcess (hprocesshandle,-1);
  8. CloseHandle (Hprocesshandle);
  9. }
  10. Else
  11. {
  12. //......  
  13. }
  14. }

Source: http://blog.csdn.net/u012372584/article/details/61912606

Right to get the process path and get a list of processes

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.