Reputation: 41
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.
For now I have a .bat file with the following code:
taskkill /F /IM chrome.exe /T > nul
del /q "C:\Users\Francisco\AppData\Local\Google\Chrome\User Data\Default\Cache\*"
FOR /D %%p IN ("C:\Users\Francisco\AppData\Local\Google\Chrome\User Data\Default\Cache\*.*") DO rmdir "%%p" /s /q
timeout 8
start chrome --restore-last-session --start-fullscreen
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.
If i remove the /f option, Chrome doesn't close:
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;
I'd prefer the first option since it's cleaner.
Upvotes: 3
Views: 19344
Reputation: 18827
Refer to the answer of @tuxy42 : You can write with vbscript to open chrome browser like this : Open_Chrome_Browser.vbs
Set ws = CreateObject("Wscript.Shell")
siteA = "https://stackoverflow.com/questions/62516355/google-chrome-always-says-google-chrome-was-not-shut-down-properly"
ws.Run "chrome -url " & siteA
And if you want to close it safely : safely_close_chrome_browser.vbs
Set ws = CreateObject("Wscript.Shell")
psCommand = "Cmd /C powershell -command ""Get-Process chrome | ForEach-Object { $_.CloseMainWindow() | Out-Null}"""
ws.run psCommand,0,True
Upvotes: 5
Reputation: 378
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}"
Upvotes: 9