0

I wanted to kill the cmd.exe process by clicking the stop button through VB script. Its not working.

The subroutine works fine if i run it separately as a .vbs file.

i even tried by keeping the subroutine code in a separate .vbs file & calling it in my html file.

<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>
webtester
  • 21
  • 6
  • 3
    You won't be able to do that out-of-the box within a browser sandbox for obvious security reasons, you could try adding the serving domain to the trusted sites zone in IE or move the script to an [HTA](http://msdn.microsoft.com/en-gb/library/ms536496(v=vs.85).aspx) if all you want is a UI – Alex K. Mar 06 '13 at 11:59
  • @AlexK. +1, I think you may post your comment as answer. – Panayot Karabakalov Mar 06 '13 at 19:44
  • Can't tskill.exe be used for this purpose? – MansoorShaikh Aug 06 '13 at 11:23

0 Answers0