Skip to content

Instantly share code, notes, and snippets.

@jmconway
Created June 10, 2021 13:49
Show Gist options
  • Save jmconway/a70c602d46d7c4631675f0561ac03692 to your computer and use it in GitHub Desktop.
Save jmconway/a70c602d46d7c4631675f0561ac03692 to your computer and use it in GitHub Desktop.
A loopy sign-on script I had a lot of fun writing for Internet Explorer (RIP). This was originally written for Windows-based "digital signage" displays that would show a printer's queue from its webpage via IE, refresh the page every 60 seconds via method, and handle relaunching were the browser to crash.
$URL = ""
$targetprocess = "iexplore"
$process = Get-Process -Name $targetprocess -ErrorAction SilentlyContinue
# Infinite loop
while ($true){
# Initial launch of the application
# While the process is not running
while (!($process)){
$process = Get-Process -Name $targetprocess -ErrorAction SilentlyContinue
# If the process STILL isn't running or has crashed
if (!($process)){
# Invoke IE ComObject with properties set for the URL specified, kept in front of all windows, and in full-screen mode
$ie = New-Object -ComObject InternetExplorer.Application -Property @{navigate2=$URL; visible = $true; fullscreen = $true}
}
# Wait between attempts to make sure the process is still running.
start-sleep -s 5
}
# If/while the process is running...
if ($process){
# Don't proceed unless the process exits...
# https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforexit?view=net-5.0#System_Diagnostics_Process_WaitForExit
$process.WaitForExit()
# If it does exit, wait a moment before calling it again
start-sleep -s 2
$process = Get-Process -Name $targetprocess -ErrorAction SilentlyContinue
$ie = New-Object -ComObject InternetExplorer.Application -Property @{navigate2=$URL; visible = $true; fullscreen = $true}
# Regardless, while the process is running, refresh the page every minute
while ($true) {
Start-Sleep -Seconds 60
$ie.Refresh()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment