powershell关闭Internet Explorer,优雅/干净

时间:2012-07-23 10:40:36

标签: internet-explorer powershell

我想干净/优雅地关闭Internet Explorer。 taskkill会关闭它,但是当重新打开它时,它会询问你是否要重新打开最后一个会话。

3 个答案:

答案 0 :(得分:7)

尝试使用CloseMainWindow方法:通过向主窗口发送关闭消息来关闭具有用户界面的进程。

Get-Process iexplore | Foreach-Object { $_.CloseMainWindow() }

答案 1 :(得分:3)

试试这个:get-process iexplore | stop-process

答案 2 :(得分:0)

这将循环并在其所有窗口上调用CloseMainWindow,即正常关闭api调用 - 它会休眠半秒以便有时间关闭每个窗口:

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