如何使用 VBScript 或 PowerShell 创建带有新图标的消息框?

How to create a message box with new icons with VBScript or PowerShell?

我已经做了一段时间的 VBScript 和 PowerShell 消息框,但是,我想使用 Windows 10 个这样的图标:

我唯一想做的就是将 Windows 7 个图标替换为 Windows 10 个图标,因为它们更现代。

有什么办法可以改变这些图标吗?

这是 PowerShell 的一个快速代码示例:

Add-Type -AssemblyName System.Windows.Forms | Out-Null
[System.Windows.Forms.Application]::EnableVisualStyles()
$btn = [System.Windows.Forms.MessageBoxButtons]::OK
$ico = [System.Windows.Forms.MessageBoxIcon]::Information
$Title = 'Welcome'
$Message = 'Hello world'
$Return = [System.Windows.Forms.MessageBox]::Show($Message, $Title, $btn, $ico)

输出:

如果我找到 VBScript 解决方案,我会跟进。

希望对您有所帮助。

作为我评论的延伸,您的查询与此 SO 线程非常相似。虽然不是特定于 PowerShell,但参考点是相同的。

This feels like a bug in user32.dll but Windows 8 has the same issue so I guess Microsoft doesn't care.

You can get the flat icon used by MessageBox by calling SHGetStockIconInfo:

SHSTOCKICONINFO sii;
    sii.cbSize = sizeof(sii);
    if (SUCCEEDED(SHGetStockIconInfo(SIID_INFO, SHGSI_ICON|SHGSI_LARGEICON, &sii)))
    {
        // Use sii.hIcon here...
        DestroyIcon(sii.hIcon);
    }

SHGetStockIconInfo is the documented way to get icons used in the Windows UI on Vista and later. Most of the icons come from imageres.dll but you should not assume that this is the case...