Rohit2194017
Rohit2194017

Reputation: 293

Powershell: how to check if any instance of internet explorer is already running

I want to check if any instance of internet explorer, ie any window of it, is already opened or not so that i can decide that a new object has to be created or i have to attach to existing process of that IE window. This is the code below:

$ie = (New-Object -COM "Shell.Application").Windows()| ? { $_.Name -eq "Windows Internet    Explorer" }

I want to attach to windows() only when a window of IE is already opened and if no IE window is opened then the line should be like this:

$ie = (New-Object -COM "Shell.Application")

Upvotes: 0

Views: 5548

Answers (2)

CB.
CB.

Reputation: 60918

try:

if (
     Get-Process iexplore -ea silentlycontinue | 
     Where-Object {$_.MainWindowTitle -ne ""}
)

Upvotes: 2

Richard
Richard

Reputation: 108995

if (Get-Process iexplore) { "Yes" } else { "No" }

I have no idea whether this works in a terminal services environment with many user (does a non-elevated Get-Process only look in your own session (and the system session) for processes?)

Upvotes: 0

Related Questions