vbs 安静且优雅的 taskkill 所有 chrome 进程

编程入门 行业动态 更新时间:2024-10-28 12:24:42
本文介绍了vbs 安静且优雅的 taskkill 所有 chrome 进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

这段代码有什么办法:

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 00:03:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1164518.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   优雅   安静   vbs   taskkill

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!