admin管理员组文章数量:1277313
I am writing using JavaScript. I have a PID of a process. How do I kill it? You can terminate by a name using WMI, How can you do it using PID?
UPDATE: The platform is Windows.
I am writing using JavaScript. I have a PID of a process. How do I kill it? You can terminate by a name using WMI, How can you do it using PID?
UPDATE: The platform is Windows.
Share Improve this question edited Feb 7, 2010 at 12:26 Andy E 345k86 gold badges481 silver badges451 bronze badges asked Feb 6, 2010 at 19:23 Boris RaznikovBoris Raznikov 2,45310 gold badges35 silver badges57 bronze badges 6- 1 kill -9 PID ??? you must be talking about a Rhino VM I guess. – jldupont Commented Feb 6, 2010 at 19:24
- 1 i doubt any system is going to let Javascript do root level mands! – PurplePilot Commented Feb 6, 2010 at 19:27
- You need to tell us in what environment this is running. Is it JScript on the Windows Script Host, for example? – Anonymous Commented Feb 6, 2010 at 19:35
- 3 @PurplePilot: Windows shell scripts can be written in Javascript (JScript). Who voted that this belongs on superuser? it's clearly a programming question. – Andy E Commented Feb 6, 2010 at 19:35
- 2 @Andy E Thanks didn't know. I think i should have qualified it being from/in a browser, which should be sandboxed. If you really tried you could run anything from anywhere ;-) – PurplePilot Commented Feb 6, 2010 at 19:55
2 Answers
Reset to default 9It 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 mand 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
mand from the shell as Andy E described in his answer..
Reference: https://web.archive/web/1/http://articles.techrepublic%2e%2e/5100-10878_11-5031568.html
本文标签: wshJavaScript killing a processStack Overflow
版权声明:本文标题:wsh - JavaScript killing a process - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741292976a2370654.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论