-2

I have done VBScript and PowerShell message boxes since a while, but, I want to use the Windows 10 icons like these:

New icons

The only thing I want to do is to replace the Windows 7 icons to the Windows 10, as they are more modern.

Is there any way to change these icons?

Anic17
  • 712
  • 5
  • 18
  • This really is not a PowerShell thing/control. These icons only exist via the .Net version that is on the box. [MessageBoxIcon Enum](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messageboxicon?view=netcore-3.1), thus if you are not running the correct .Net version on your OS, you can't do this regardless of language. What you can do is create your own msgbox (winform/wpf) form, create your own icons, from the Win10 ones and embed that in your code. – postanote Jun 08 '20 at 04:43

2 Answers2

0

Here's one quick code example for 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)

Output:

enter image description here

If I find a VBScript solution, I'll follow-up.

Hope this helps.

leeharvey1
  • 1,316
  • 9
  • 14
0

As an extension of my comment, your query is very similar to this SO thread. Though not specific to PowerShell, the reference point is the same.

How can I load the same icon as used by MessageBox on Windows 10?

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...

postanote
  • 15,138
  • 2
  • 14
  • 25