How to Kill a Task by VBS

VBScript (VBS) allows you to create small offline or online applications that perform small tasks, such as running a process at a scheduled time. When you have no access to the task manager or command prompt, but you really need to kill a process, you may write a script that kills it through an automated process. VBS does not natively have a certain function for killing processes, meaning that you must work around its scripting interface to properly kill a task.

Instructions

    • 1

      Click your "Start" menu, click "All Programs," click "Accessories" and click "Notepad."

    • 2

      Type the following on the first line:

      sComputerName = "."

    • 3

      Start a new line and type the following:

      sTask = "task.exe"

      Replace "task.exe" with the process name you would like to kill.

    • 4

      Type the following on a new line:

      SET oWMI = GETOBJECT("winmgmts:" & "{impersonationLevel=impersonate}!\\" & sComputerName & "\root\cimv2")

      This gets the Windows Management Instrumentation interface for your computer and puts it into an object.

    • 5

      Start another line and type this code:

      SET cTask = oWMI.ExecQuery ("Select * from Win32_Process Where Name = '" & sTask & "'")

      This defines "cTask" as the object for the process you try to kill.

    • 6

      Type the following code in its exact context:

      FOR EACH oTask in cTask

      oTask.Terminate()

      NEXT

      This kills all the tasks with the name you specified in "sTask."

    • 7

      Click "File" and "Save As" in your Notepad window. Select "All Files" under "Save as type" and type "killtask.vbs" as the file name. Click "Save." Browse to the location where you saved your file and open it. This automatically kills the process.

Tips & Warnings

  • Do not kill a process that prevents the administrator of your system, if not yourself, from properly having control over the computer. Doing this has its repercussions. Use this knowledge only to troubleshoot your computer if you do not have access to the task manager or command line.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured