用 PowerShell 弹出 Windows 对话框
显示带标题和按钮的原生消息框。
运行该片段会弹出消息框,点击“确定”关闭。
01命令
命令
$ Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show("Hello from PowerShell","cmdcv")02作用说明
加载 System.Windows.Forms 后即可在 PowerShell 中使用 Win32 的 MessageBox API。第二个参数是标题,第三个参数可选择按钮和图标;返回值表明用户点击了哪个按钮,因此脚本可以询问用户。
03风险
!注意: 消息框会阻塞直到被关闭,绝不要在无人值守或计划任务脚本中调用。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- MessageBox Class依据: Displays a message window to the user; Show returns the clicked button.
最后验证: 2026-09-20 · 分类: 系统与设置