Here I have the same MessageBox function realized in Winforms and WPF. They show up as expected if I simply call them, but if I call them after a Get-Credential prompt as in this example they are hidden behind the ISE window. I’m running PS 5.0 on Windows 10. On Windows 7 and PS ISE 5.0 the Winforms version shows up topmost but WPF does not. I tried adding $Form.Focus() or $Window.Focus() with no effect. How can I ensure that the user gets error messages?
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName PresentationFramework
function MessageBoxWF ($Message, $Title) {
$Form = New-Object 'System.Windows.Forms.Form'
$Form.TopMost = $true
[System.Windows.Forms.MessageBox]::Show($Form, $Message, $Title, 0, 48)
$Form.Close()
$Form.Dispose()
}
function MessageBoxWPF ($Message, $Title) {
$Window = New-Object 'System.Windows.Window'
$Window.TopMost = $true
[System.Windows.MessageBox]::Show($Window, $Message, $Title, 'OK', 'Exclamation')
}
$cred = Get-Credential 'User'
MessageBoxWPF "Error message." "Error" > $null