# PSIEDisplay.ps1 # PowerShell script to use Microsoft Internet Explorer to display a # dynamic dialog box indicating program progress. # # ---------------------------------------------------------------------- # Copyright (c) 2011 Richard L. Mueller # Hilltop Lab web site - http://www.rlmueller.net # Version 1.0 - March 29, 2011 # # You have a royalty-free right to use, modify, reproduce, and # distribute this script file in any way you find useful, provided that # you agree that the copyright owner above has no warranty, obligations, # or liability for such use. Trap {"Error: $_"; Break;} $IE = New-Object -ComObject "InternetExplorer.Application" $Title = "Test Program" $Width = $IE.Width $Height = $IE.Height $IE.ToolBar = 0 $IE.StatusBar = $False $IE.Resizable = $False $IE.Navigate("about:blank") While ($IE.ReadyState -ne 4) { Start-Sleep -milliseconds 200 } $IE.Document.Body.InnerText = "Program initializing..." $IE.Document.Title = $Title $IE.Document.Body.Scroll = "no" $IE.Document.Body.Style.Font = "10pt 'Courier New'" $IE.Document.Body.Style.BorderStyle = "outset" $IE.Document.Body.Style.BorderWidth = "4px" $IE.Document.Body.Style.BackgroundColor = "LightBlue" # Specify the size of the dialog box. $IE.Height = $Height * .35 $IE.Width = $Width * .60 # Position the dialog box on the screen. $IE.Top = 200 $IE.Left = 300 $IE.Visible = $True Start-Sleep -s 3 $Close = $False For ($k = 0; $k -le 10; $k = $k + 1) { # An error is raised if the user closes the dialog box. Try { $IE.Document.Body.InnerText = "Iteration $k`nTo abort, close this box" Start-Sleep -s 1 } Catch { # The user closed the dialog box. $k = $k - 1 "Program aborted after $k iterations" $Close = $True Break } } If ($Close -eq $False) { $IE.Document.Body.InnerText = "Loop complete" Start-Sleep -s 2 $IE.Document.Body.InnerText = "Program Finished" Start-Sleep -s 2 $IE.Document.close() $IE.Quit() } "Done"