[scripting] How to stop a vb script running in windows

I'm using windows 7

I wrote a script to check whether My Laptop is running in Battery or AC current. I googled it and succedded in that.

dim a
a=1
Do While a=1 
If IsLaptop( "." ) Then
   ' WScript.Echo "Laptop"
Else
   ' WScript.Echo "Desktop or server"
End If
Loop

Function IsLaptop( myComputer )
    On Error Resume Next    
    Set objWMIService = GetObject( "winmgmts://" & myComputer & "/root/cimv2" )
    Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", , 48 )
    IsLaptop = False
    For Each objItem in colItems
        if objItem.BatteryStatus=2 and objItem.EstimatedChargeRemaining=98 then
             WScript.Echo "Remove Ac Adapter Immediately"
        elseif objItem.BatteryStatus=1 and objItem.EstimatedChargeRemaining=10 then
             WScript.Echo "Pluggin to charger immediately"
        end if
    Next
    If Err Then Err.Clear
    On Error Goto 0
End Function

But my problem now is. This script is ever running script how to stop if i wish to terminate manually.

Is there any way i go and find this process and stop in windows?

This question is related to scripting vbscript windows-scripting

The answer is


I can think of at least 2 different ways:

  1. using Task Manager (Ctrl-Shift-Esc), select the process tab, look for a process name cscript.exe or wscript.exe and use End Process.

  2. From the command line you could use taskkill /fi "imagename eq cscript.exe" (change to wscript.exe as needed)

Another way is using scripting and WMI. Here are some hints: look for the Win32_Process class and the Terminate method.


Create a Name.bat file that has the following line in it.

taskkill /F /IM wscript.exe /T

Be sure not to overpower your processor. If you're running long scripts, your processor speed changes and script lines will override each other.


Running scripts can be terminated from the Task Manager.

However, scripts that perpetually focus program windows using .AppActivate may make it very difficult to get to the task manager -i.e you and the script will be fighting for control. Hence i recommend writing a script (which i call self destruct for obvious reasons) and make a keyboard shortcut key to activate the script.

Self destruct script:

Option Explicit
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "taskkill /f /im Cscript.exe", , True 
WshShell.Run "taskkill /f /im wscript.exe", , True  

Keyboard shortcut: rightclick on the script icon, select create shortcut, rightclick on script shortcut icon, select properties, click in shortcutkey and make your own.

type your shortcut key and all scripts end. Cheers


in your code, just after 'do while' statement, add this line..

`Wscript.sleep 10000`

This will let your script sleep for 10 secs and let your system take rest. Else your processor will be running this script million times a second and this will definitely load your processor.

To kill it, just goto taskmanager and kill wscript.exe or if it is not found, you will find cscript.exe, kill it pressing delete button. These would be present in process tab of your taskmanager.

Once you add that line in code, I dont think you need to kill this process. It will not load your CPU.

Have a great day.


Start Task Manager, click on the Processes tab, right-click on wscript.exe and select End Process, and confirm in the dialog that follows. This will terminate the wscript.exe that is executing your script.