开发者

JavaScript killing a process

开发者 https://www.devze.com 2022-12-19 04:05 出处:网络
I am writing using JavaScript. I have a PID of a process. H开发者_JS百科ow do I kill it? You can terminate by a name using WMI, How can you do it using PID?

I am writing using JavaScript. I have a PID of a process. H开发者_JS百科ow do I kill it? You can terminate by a name using WMI, How can you do it using PID?

UPDATE: The platform is Windows.


It looks like you're coding for either Windows Script Host or a Windows Desktop Gadget. If it is, I would use WScript.Shell and its Exec method along with the command line taskkill (Win XP Pro, Win Vista & Win 7 only):

var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("taskkill /pid 1234");

If you really want to do it with WMI something like the following works fine for me (thanks @Helen for the improvements):

function killPID (pid) {
  GetObject("winmgmts:").Get("Win32_Process.Handle='" + pid + "'").Terminate();
}


For Windows 2000 you will need to install the Windows Support Tools and then use the Kill command from the shell as Andy E described in his answer..

Reference: https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5031568.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号