powershell close internet explorer gracefully / cl

2019-04-09 03:40发布

问题:

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}"