I would like to close internet explorer cleanly/ gracefully. A taskkill would close it but when re-opening it it will ask if you want to re-open the last session.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Try the CloseMainWindow method: Closes a process that has a user interface by sending a close message to its main window.
Get-Process iexplore | Foreach-Object { $_.CloseMainWindow() }
回答2:
Try this: get-process iexplore | stop-process
.
回答3:
This will loop around and call CloseMainWindow on all its windows, that is the graceful shutdown api call - it sleeps half a second to give it time to close each before going around:
powershell -Command "while ($true){Try{$process=Get-Process iexplore -ErrorAction Stop}Catch [Microsoft.PowerShell.Commands.ProcessCommandException]{break;}if ($process) {$whateva=$process.CloseMainWindow()}else {break;}Start-Sleep -m 500}"