vbs 安静且优雅的 taskkill 所有 chrome 进程 [英] vbs silent and graceful taskkill all chrome process

查看:126
本文介绍了vbs 安静且优雅的 taskkill 所有 chrome 进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码有什么办法:

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.Run "taskkill /im chrome.exe", 0, True

我希望它关闭所有正在运行的 chrome 实例,而不是像这个脚本那样只安静优雅地关闭一个 chrome 窗口.

Instead of only closing only one window of chrome silently and gracefully like this script already does, I want it to close all running instances of chrome.

如果有一种简单的方法可以使用此代码关闭所有 chrome 窗口而无需循环,那就太完美了.

If there is a simple way to close all windows of chrome without a loop with this code, that would be perfect.

我已经尝试了所有其他方法,但它们要么没有正常关闭(终止),要么显示某种命令提示符或加载栏.

I have already tried all other methods, but they all either didn't close gracefully, (terminate), or they showed some sort of command prompt or loading bar.

如果没有循环就没有办法做到这一点,那就这样吧.

If there isn't any way to do this without a loop, then so be it.

谢谢!

推荐答案

我们可以使用 WMI 服务执行此操作.我们可以统计一下chrome的所有运行实例,然后默默的一一杀掉.

We can perform this using WMI service . We can count all the running instances of chrome and then silently kill it one by one.

希望这有帮助.它涉及循环.

Hope this helps . It involves looping .

Dim oShell, objWMIService, objProcess, colProcess, strComputer, processName,instances

strComputer = "."
instances = 0
processName = "chrome.exe"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process")

For Each objProcess in colProcess
If objProcess.Name = processName Then instances = instances + 1        'Incrementing Running Instances
Next

Set oShell = WScript.CreateObject ("WScript.Shell")

Do While instances > 0
oShell.Run "taskkill /im chrome.exe", 0, True       'Killing one instance at a time
instances = instances - 1
Loop

这篇关于vbs 安静且优雅的 taskkill 所有 chrome 进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆