- PopUpButtons: Set buttons that will be displayed on the popup window. Default value set to show only the OK button
- PopUpIcon: Set Icon used for the popup window. Default value set to use the Information icon.
- PopUpTime: Set timeout for the popup window. After the specified time is expired the popup window will be closed automaticaly. Default set to unlimited.
- PopUpTitel: Set title of the popup window.
- PopUpMessage: Set message to show on the popup window.
Return value depend on the button clicked or is -1 if the message box timed out. The possible values are:
OK button clicked: 1
Cancel button clicked: 2
Abort button clicked: 3
Retry button clicked: 4
Ignore button clicked: 5
Yes button clicked: 6
No button clicked: 7
Try Again button clicked: 10
Continue button clicked: 11
$ButtonClicked = Show-PopUp -PopUpButtons AbortRetryIgnore -PopUpIcon Question -PopUpTitel "Abort Retry Ignore" -PopUpMessage "press Abort, Retry or Ignore button"
<#
.SYNOPSIS
Show popUp
.DESCRIPTION
Function shows message as a PopUp
PopUp Type: 0 | OK Only; 1 | OK and Cancel
#>
Param (
[ValidateSet ('OK', 'OKCancel', 'AbortRetryIgnore', 'YesNoCancel', 'YesNo', 'RetryCancel', 'CancelTryAgainContinue')]
[string]
$PopUpButtons = 'OK',
[ValidateSet ('Error', 'Question', 'Exclamation', 'Information')]
[string]
$PopUpIcon = 'Information',
[int]
$PopUpTime = 0,
[Parameter (Mandatory=$true)]
[string]
$PopUpTitel,
[Parameter (Mandatory=$true)]
[string]
$PopUpMessage
)
# PopUp/MessageBox() Flags
# Popup Buttons
[int]$PopupOK = 0 # 1
[int]$PopupOKCancel = 1 # 1|2
[int]$PopupAbortRetryIgnore = 2 # 3|4|5
[int]$PopupYesNoCancel = 3 # 6|7|2
[int]$PopupYesNo = 4 # 6|7
[int]$PopupRetryCancel = 5 # 4|2
[int]$PopupCancelTryAgainContinue = 6 # 2|10|11
# Popup Icons
[int]$PopupIconError = [int]0x10 # X
[int]$PopupIconQuestion = [int]0x20 # ?
[int]$PopupIconExclamation = [int]0x30 # !
[int]$PopupIconInformation = [int]0x40 # i
# PopUp Focus
[int]$PopupSetForegrund = [int]0x10000
[int]$PopupTopMost = [int]0x40000
[int]$PopupSystemModal = [int]0x1000
[int]$PopupSecondButtonDefault = [int]0x100
[int]$PopupThirdButtonDefault = [int]0x200
# Show PopUp Message
$temp = new-object -comobject wscript.shell
# Set PopUp type - Button(s) and Icon
switch ($PopUpButtons) {
'OK' {$PopUpType = $PopupOK}
'OKCancel' {$PopUpType = $PopupOKCancel}
'AbortRetryIgnore' {$PopUpType = $PopupAbortRetryIgnore}
'YesNoCancel' {$PopUpType = $PopupYesNoCancel}
'YesNo' {$PopUpType = $PopupYesNo}
'RetryCancel' {$PopUpType = $PopupRetryCancel}
'CancelTryContinue' {$PopUpType = $PopupCancelTryContinue}
}
switch($PopUpIcon) {
'Error' {$PopUpType += $PopupIconError}
'Question' {$PopUpType += $PopupIconQuestion}
'Exclamation' {$PopUpType += $PopupIconExclamation}
'Information' {$PopUpType += $PopupIconInformation}
}
$PopUpClicked = $temp.PopUp($PopUpMessage,$PopUpTime,$PopUpTitel,$PopUpType+$PopupTopMost)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($temp) | Out-Null
Remove-Variable temp
# Return Clicked Button. OK = 1|Cancel=2
Write-Output $PopUpClicked
}