scripting - 如何停止Windows中运行的VB脚本

标签 scripting vbscript windows-scripting

我正在使用Windows 7

我编写了一个脚本来检查我的笔记本电脑是否以电池或交流电运行。
我用谷歌搜索并成功了。

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

但是我现在的问题是。此脚本曾经运行过的脚本,如果我希望手动终止,该如何停止。

有什么办法可以找到这个过程并在Windows中停止吗?

最佳答案

我可以想到至少两种不同的方式:

使用任务管理器(Ctrl-Shift-Esc)的

  • ,选择“进程”选项卡,查找进程名称cscript.exe或wscript.exe,然后使用“结束进程”。
  • 在命令行中,您可以使用taskkill/fi“imagename eq cscript.exe”(根据需要更改为wscript.exe)

  • 另一种方法是使用脚本和WMI。这里有一些提示:查找Win32_Process类和Terminate方法。

    关于scripting - 如何停止Windows中运行的VB脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8017850/

    相关文章:

    linux - Shell 函数提前退出而不是遍历所有内容

    sql - VBS脚本执行SQL语句?

    vbscript - 检查某个值是否在数字列表中

    windows - JScript 是否支持字符串修剪方法?

    c# - 使用 Windows 脚本宿主

    linux - bash shell 脚本 101 - 在脚本中循环

    Python:检测文本文件中是否只出现给定的单词之一

    linux - 根据时间启动和终止进程

    vbscript - 文件路径中有空格的 VBS

    powershell - 挂载/卸载ISO并运行程序