GiantDuck
GiantDuck

Reputation: 1064

Maintain single instance of start-process

I am using powershell on Windows 8. I am using this line of code...

start-process -filepath "C:\Program Files\Internet Explorer\iexplore.exe" -argumentlist "-k http://localhost/"

...to start IE. This works, however, when the event is triggered multiple times, multiple instances of kiosk IE are opened. How can I maintain a single instance of kiosk IE, and later close it programmatically?

Thank you! :)

Upvotes: 0

Views: 673

Answers (1)

Micky Balladelli
Micky Balladelli

Reputation: 10001

Would this work?

$ie = Get-Process -Name iexplore -ErrorAction SilentlyContinue

if ($ie -eq $null)
{
    start-process -filepath "C:\Program Files\Internet Explorer\iexplore.exe" -argumentlist "-k http://localhost/"
}

To stop the running instance you can do this:

$ie = Get-Process -Name iexplore -ErrorAction SilentlyContinue

if ($ie -ne $null)
{
    $ie | Stop-Process
}

EDIT: You can also combine the two to ensure IE is not running before you start your process and if it is, it will be stopped:

Get-Process -ErrorAction SilentlyContinue -Name iexplore | Stop-Process -ErrorAction SilentlyContinue
start-process -filepath "C:\Program Files\Internet Explorer\iexplore.exe" -argumentlist "-k http://localhost/"

Upvotes: 1

Related Questions