通过Vbscript杀死命令提示符进程

时间:2013-03-06 11:53:33

标签: vbscript

我想通过VB脚本单击停止按钮来终止cmd.exe进程。它不起作用。

如果我将它作为.vbs文件单独运行,子例程就可以正常工作。

我甚至尝试将子程序代码保存在单独的.vbs文件中。在我的html文件中调用它。

<html>
<head> 
<SCRIPT LANGUAGE="VBScript"> 

Sub stopbtn_OnClick

   MsgBox "Mirabile visu."

 strComputer = "."
 strProcessToKill = "cmd.exe" 

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _ 
    & strComputer & "\root\cimv2") 

Set colProcess = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")

count = 0
For Each objProcess in colProcess
    objProcess.Terminate()
    count = count + 1
Next 

wscript.echo "Killed " & count & " instances of " & _
    strProcessToKill & "on " & strComputer

End Sub

</SCRIPT>
</head>
<body>
<form name="stoprc">
 <tr>
      <td width="80"></td>
      <td><input type="button" value="Stop" name="stopbtn" ></td>
   </tr>
</form>
<body>
</html>

0 个答案:

没有答案