How to kill Processes running under different users using c++ code -
the following code works fine in displaying process id of processes (eg: notepad.exe) running under different users. process under current user alone getting killed. need kill processes running under different users.
#define sampleapp "notepad.exe" void main() { killprocessbyname(sampleapp); system("pause"); } void killprocessbyname(const char *filename) { // taking snapshot of processes handle hsnapshot = createtoolhelp32snapshot(th32cs_snapall, null); //structure capture each entry in snapshot processentry32 pentry; pentry.dwsize = sizeof (pentry); //capture first process in list bool hres = process32first(hsnapshot, &pentry); while (hres) { char tempprocess[process_size];// = pentry.szexefile; wcstombs(tempprocess, pentry.szexefile, process_size); //if process name equal process passed argument killed if (strcmp(tempprocess, filename) == 0) { handle hprocess = openprocess(process_terminate, 0, (dword) pentry.th32processid); std::cout << "process id of process " << tempprocess << " : " << pentry.th32processid; if (hprocess != null) { // kill process terminateprocess(hprocess, 9); closehandle(hprocess); } } //capture next process in process snapshot hres = process32next(hsnapshot, &pentry); } closehandle(hsnapshot); }
how can kill process, if belongs user?
right-click program, , select "run administrator".
Comments
Post a Comment