0

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! :)

GiantDuck
  • 1,086
  • 3
  • 14
  • 27

1 Answers1

1

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/"
Micky Balladelli
  • 9,781
  • 2
  • 33
  • 31
  • Thanks! This works unless IE is already open on the machine. I gave you an upvote, but this doesn't quite answer my question. – GiantDuck Nov 29 '14 at 12:45
  • This will only start iexplore if it's not running. Do you want to close it if it's running before starting a new process? Changed the answer to address that as well if it's the case. – Micky Balladelli Nov 29 '14 at 12:55