0

我想通过 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>
4

0 回答 0