1, the process to raise the right:
- BOOL Cprogressinfo::adjustprivileges ()
- {
- HANDLE htoken = NULL;
- token_privileges TP = {0};
- Token_privileges OLDTP = {0};
- DWORD dwsize = sizeof (token_privileges);
- LUID LUID = {0};
- if (! OpenProcessToken (GetCurrentProcess (), Token_adjust_privileges | Token_query, &htoken)) {
- if (GetLastError () ==error_call_not_implemented)
- return TRUE;
- Else
- return FALSE;
- }
- if (! Lookupprivilegevalue (NULL, Se_debug_name, &luid)) {
- CloseHandle (Htoken);
- return FALSE;
- }
- Tp. Privilegecount=1;
- Tp. Privileges[0]. Luid = Luid;
- Tp. Privileges[0]. Attributes = se_privilege_enabled;
- / * Adjust Token privileges * /
- if (! AdjustTokenPrivileges (Htoken, FALSE, &TP, sizeof (token_privileges), &OLDTP, &dwsize)) {
- CloseHandle (Htoken);
- return FALSE;
- }
- //Close handles
- CloseHandle (Htoken);
- return TRUE;
- }
2. Get the process list (you can get the basic process path after the right):
- BOOL cprogressinfo::getprogresslist ()
- {
- BOOL bresult = FALSE;
- HANDLE hsnap = createtoolhelp32snapshot (th32cs_snapprocess, 0);
- if (Hsnap = = Invalid_handle_value)
- return FALSE;
- HANDLE hprocess = NULL;
- PROCESSENTRY32 info = {0};
- Info.dwsize = sizeof (PROCESSENTRY32);
- BOOL bRet = Process32First (Hsnap, &info);
- While (BRet) {
- hprocess = OpenProcess (process_query_information | Process_vm_read, FALSE, Info.th32processid);
- if (hprocess) {
- Getmodulefilenameex (hprocess, NULL,/ * buffer pointer */, MAX_PATH); Get process Path
- }
- BRet = Process32Next (Hsnap, &info);
- }
- return TRUE;
- }
3, according to the process of PID, to end this process:
- void Cprogressinfo::D eleteprogress (DWORD PUID)
- {
- HANDLE Hprocesshandle;
- Hprocesshandle =:: OpenProcess (Process_terminate, False,puid);
- if (hprocesshandle)
- {
- TerminateProcess (hprocesshandle,-1);
- CloseHandle (Hprocesshandle);
- }
- Else
- {
- //......
- }
- }
Source: http://blog.csdn.net/u012372584/article/details/61912606
Right to get the process path and get a list of processes