Diese Messagebox könnte man einsetzen, nachdem eine Softwareinstallation abgeschlossen wurde.
Der Aufruf könnte so erfolgen:
- #MessageBox Sample
- ###############################
-
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
-
- $dForm = New-Object System.Windows.Forms.Form
- $dForm.Size = new-object System.Drawing.Size 640,200
- $dForm.Text = "Adobe Acrobat Professional"
- $dText = New-Object System.Windows.Forms.TextBox
- $dText.ScrollBars = "none"
- $dText.Dock = "fill"
- $dText.Multiline = $true
- $dText.Parent = $dForm
- $dText.ReadOnly = $true
-
- #Add-TextToWindow "The date is $(get-date)`n"
- Add-TextToWindow "Um die Installation des Programms abzuschliessen ist ein Neustart erforderlich. Dieser wird nicht automatisch durchgeführt!`n"
- Add-TextToWindow "`n"
- Add-TextToWindow "`n"
- Add-TextToWindow "The system needs to be restarted to finish the installation. The restart will not be done automatically!"
-
- $dForm.Add_Shown({$dform.Activate()})
- #
- # Create the new runspace
- #
- $rs = [Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
- $rs.Open()
-
- # pass in the form object...
-
- $rs.SessionStateProxy.SetVariable("dForm", $dForm)
-
- # and set up a synchronized data interchange object
- # between the two runspaces...
-
- $data = [hashtable]::Synchronized(@{text=""})
- $rs.SessionStateProxy.SetVariable("data", $data)
-
- # Start the pipeline so the form will display...
-
- $p = $rs.CreatePipeline({ [void] $dForm.ShowDialog()})
- $p.Input.Close()
- $p.InvokeAsync()
- function Add-TextToWindow($text)
- {
- [eventhandler] $eh = {
- $this.AppendText($data.text)
- }
- $data.text = $text
- do {
- $retry = @($false)
- trap [InvalidOperationException] {
- start-sleep -milli 100
- $retry[0] = $true
- continue
- }
- $dText.Invoke($eh, ($dText, [eventargs]::empty))
- } while ($retry[0])
- }