How to properly close Internet Explorer when launched from PowerShell?

后端 未结 6 1919
长情又很酷
长情又很酷 2020-12-06 06:43

There was a set of recently asked questions about doing something with Internet Explorer via PowerShell. All of them contain codes to launch IE from PowerShell as an object,

6条回答
  •  眼角桃花
    2020-12-06 07:13

    With a quick look around in the ComObject for IE, it seems that when it is created, it gives you a direct interface to the methods that make interacting with IE easier, for example Navigate() or ReadyState.

    I did discover a property that seems to be what you are looking for and that would be Parent

    Calling $IE.Parent.Quit() seemed to get rid of the PowerShell created instances.

    $IE = New-Object -ComObject InternetExplorer.Application
    Get-Process | Where-Object {$_.Name -Match "iex"}
    
    Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
    -------  ------    -----      ----- -----   ------     -- -----------
        291      20     5464      14156   200     0.16   1320 iexplore
        390      30     5804      20628   163     0.14   5704 iexplore
    
    $IE.Parent.Quit()
    (Get-Process | Where-Object {$_.Name -Match "iex"}).GetType()
    You cannot call a method on a null-valued expression...
    

提交回复
热议问题