Created
August 24, 2014 09:41
-
-
Save bedefaced/b9a3952f69336e7b3b55 to your computer and use it in GitHub Desktop.
pkill for Windows (WSH)
This file contains hidden or 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
var objArgs = WScript.Arguments; | |
if (objArgs.length == 0) WScript.Quit(0); | |
var filter = objArgs(0); | |
var objProcess = GetObject("winmgmts:\\\\.\\root\\cimv2"); | |
var listPIDs = new Enumerator(objProcess.ExecQuery("SELECT Handle, CommandLine FROM Win32_Process " + | |
"WHERE Name LIKE '%" + filter + "%' OR CommandLine LIKE '%" + filter + "%'")); | |
for ( ; !listPIDs.atEnd(); listPIDs.moveNext()) { | |
var process = listPIDs.item(); | |
if (process.CommandLine.indexOf(WScript.ScriptName) < 0) | |
objProcess.Get("Win32_Process.Handle='" + process.Handle + "'").Terminate(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment