The only way I could get this to shutdown gracefully was to use taskkill.exe inside the VBS file. This would allow me to open Chrome (after it had been closed programmatically) without the error message that it had be closed improperly.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Chrome.exe'")
Set oShell = CreateObject("WScript.Shell")
For Each objProcess in colProcessList
oShell.Run "taskkill /im chrome.exe", , True
Next
Honestly though, if you're new to VBS, then you might consider being new to PowerShell instead. Here's what this looks like in PowerShell:
Get-Process -Name 'chrome' | Stop-Process -Force
Note: This one seems to be hit or miss on whether Chrome reports it was closed improperly or not, so.... Here's PowerShell using taskkill. Notice that this example uses taskkill's /pid switch and not the /im switch from the VBS example above. Have fun!
$Chrome = Get-Process -Name chrome | select -ExpandProperty ID
Foreach ($C in $Chrome) {
taskkill /pid $C
}
Edit: Added PowerShell examples
-
Edited by
tommymaynard
Tuesday, April 29, 2014 9:16 PM
-
Marked as answer by
TWRX79
16 hours 8 minutes ago