How to stop vb script in windows

I am using windows 7

I wrote a script to check if My Laptop is working in Battery or AC current. I looked for her and succeeded in this.

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 now my problem. This script works as a stop script if I want to finish manually.

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

+4
source share
5 answers

I can think at least differently:

  • using the task manager (Ctrl-Shift-Esc), select the process tab, find the process name cscript.exe or wscript.exe and use End Process.

  • At the command line, you can use taskkill / fi "imagename eq cscript.exe" (if necessary, change to wscript.exe)

Another way is to use scripts and WMI. Here are some suggestions: find the Win32_Process class and the Terminate method.

+12
source

Scripting can be stopped from the task manager.

However, scripts that constantly focus program windows using .AppActivate can make it difficult to access the task manager — you and the script will struggle to control it. Therefore, I recommend writing a script (which I call self destruct for obvious reasons) and making a key combination to activate the script.

Self Destruction 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 shortcut creation, rightclick on the script icon shortcut, select properties, click on the quick access link and make your own.

enter your key combination and all scripts will complete. Greetings

+4
source

in your code, immediately after the do-by-now instruction, add this line.

 `Wscript.sleep 10000` 

This will allow your host script to sleep for 10 seconds and allow your system to rest. Otherwise, your processor will run this script millions of times per second, and this will definitely load your processor.

To kill it, just go to taskmanager and run wscript.exe, or if it is not found, you will find cscript.exe, kill it by pressing the delete button. They will be present on the process tab of your task manager.

As soon as you add this line to the code, I don't think you need to kill this process. It will not load your processor.

Have a great day.

+2
source

Launch the task manager, go to the "Processes" tab, right-click the wscript.exe file and select "End the process" and confirm it in the next dialog box. This will cause wscript.exe to complete running your script.

+1
source

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

 taskkill /F /IM wscript.exe /T 

Be sure not to overload the processor. If you use long scripts, the processor speed will change, and the script lines will override each other.

0
source

Source: https://habr.com/ru/post/1379746/


All Articles