Created
April 5, 2011 01:45
-
-
Save hpcx82/902868 to your computer and use it in GitHub Desktop.
A program to terminate all processes of same name in Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <Tlhelp32.h> | |
int _tmain(int argc, const TCHAR* argv[]) | |
{ | |
if(argc != 2) return -1; | |
TCHAR* processName = argv[1]; | |
PROCESSENTRY32 ppe = {0}; | |
ppe.dwSize = sizeof (PROCESSENTRY32); | |
HANDLE hSnapShot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0); | |
if (Process32First (hSnapShot, &ppe)) | |
{ | |
do | |
{ | |
// Process name match (and it is not current process) | |
if (!_tcsicmp (processName, ppe.szExeFile) && (ppe.th32ProcessID != GetCurrentProcessId ())) | |
{ | |
HANDLE hMySecondProcess = OpenProcess (PROCESS_TERMINATE, FALSE, ppe.th32ProcessID); | |
if (hMySecondProcess) | |
{ | |
TerminateProcess (hMySecondProcess, 0); | |
} | |
CloseHandle (hMySecondProcess); | |
} | |
}while (Process32Next (hSnapShot, &ppe)); } | |
CloseHandle (hSnapShot); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment