如何使用 CMD 或 VBS 轻轻关闭 Chrome? [英] How to gently close Chrome using CMD or VBS?

查看:138
本文介绍了如何使用 CMD 或 VBS 轻轻关闭 Chrome?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在轻轻关闭 Chrome 以自动清理缓存时遇到了一个小问题.

I'm having a little problem about closing gently Chrome in order to automatically clean cache.

我有一个网站无法正确刷新,但如果我清理缓存,它会刷新.

I have a website that is not refreshing correctly, but it does if I clean the cache.

现在我有一个包含以下代码的 .bat 文件:

For now I have a .bat file with the following code:

taskkill /F /IM chrome.exe /T > nul
del /q "C:UsersFranciscoAppDataLocalGoogleChromeUser DataDefaultCache*"
FOR /D %%p IN ("C:UsersFranciscoAppDataLocalGoogleChromeUser DataDefaultCache*.*") DO rmdir "%%p" /s /q
timeout 8
start chrome --restore-last-session --start-fullscreen

现在,我知道 taskkill/F 会强制关闭进程并且可以正常工作,但是一旦 Chrome 打开,它就会显示一条消息,表明 Chrome 未正确关闭,并询问我是否需要恢复上次会话.

Now, I know that taskkill /F forces the process to close and that works but as soon as Chrome opens, it shows a message that Chrome wasn't closed correctly and asks me if I want to restore the last session.

如果我删除/f 选项,Chrome 不会关闭:

If i remove the /f option, Chrome doesn't close:

ERROR: PID 为 8580 的进程(PID 辅助进程 8896)无法完成.
原因:这个进程只能强行终止(使用/F选项).

ERROR: the process with PID 8580 (PID secondary process 8896) Could not finish.
Reason: This process can be terminated only forcibly (with the / F option).

所以...我需要两个选项之一;

So... I need one of two options;

  1. 有没有办法像使用 CMD 或 VBS 按下 Alt+F4 一样轻轻关闭 Chrome?2.有没有办法隐藏 Chrome 恢复上次会话消息?

我更喜欢第一个选项,因为它更干净.

I'd prefer the first option since it's cleaner.

推荐答案

您可以使用 powershell 关闭所有以 chrome 作为进程名称的窗口.它不会终止任务,但会轻轻关闭所有 chrome 浏览器窗口,就像您单击右上角的十字一样.这是批处理的命令行:

you can use powershell to close all windows with chrome as process name. It won't kill the task but gently close all chrome browser windows, like if you clicked on top-right cross. Here is the command line to put in batch :

powershell -command "Get-Process chrome | ForEach-Object { $_.CloseMainWindow() | Out-Null}"

这篇关于如何使用 CMD 或 VBS 轻轻关闭 Chrome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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