PowerShell 技能连载 - 显示警告对话框(第 1 部分)

这是一个显示弹出警告对话框的快速代码示例:

1
2
3
4
5
Add-Type -AssemblyName  System.Windows.Forms
$message = 'Your system will shutdown soon!'
$title = 'Alert'

[System.Windows.Forms.MessageBox]::Show($message, $title, [System.Windows.Forms.MessageBoxButtons]::OKCancel, [System.Windows.Forms.MessageBoxIcon]::Warning)

这些是可用的按钮样式:

1
2
3
4
5
6
7
PS> [Enum]::GetNames([System.Windows.Forms.MessageBoxButtons])
OK
OKCancel
AbortRetryIgnore
YesNoCancel
YesNo
RetryCancel

这些是可用的图标样式:

1
2
3
4
5
6
7
8
9
10
PS> [Enum]::GetNames([System.Windows.Forms.MessageBoxIcon])
None
Hand
Error
Stop
Question
Exclamation
Warning
Asterisk
Information
评论