UAC shield icon incompatibility between Vista and 7

UAC shield icon on Windows 7 is different from those on Vista. Those on 7 is colored with blue and yellow. Those on Vista is with the four colors (red, green, blue and yellow.) But any document associate with this fact is not found.
So I think following program have version incompatibility:
- using the icon which is in your program's resource
- using
SystemIcons.Shield
(.NET Framework)
Why SystemIcons.Shield
has incompatibility? SystemIcons.Shield
yields an four-colors shield icon even if the program is running on windows 7. So, I think SystemIcons.Shield
shall not be used for UAC.
Using SHGetStockIconInfo()
with SIID_SHIELD
seems to be a correct answer. This code return the UAC shield icon colored with blue and yellow on windows 7, and colored with four colors on Vista. Example code is as follows:
SHSTOCKICONINFO sii;
sii.cbSize = sizeof(SHSTOCKICONINFO);
SHGetStockIconInfo(SIID_SHIELD, SHGSI_ICON, &sii);
sii.hIcon; // this is a UAC shield icon handler!
If your program is a .NET Framework application, P/Invoke is required such as following code. Another example code is also available at CodeProject.
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
struct SHSTOCKICONINFO
{
public Int32 cbSize;
public IntPtr hIcon;
public Int32 iSysImageIndex;
public Int32 iIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
public string szPath;
}
[DllImport("shell32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
static extern void SHGetStockIconInfo(UInt32 siid, UInt32 uFlags,
ref SHSTOCKICONINFO sii);
Note that SIID_SHIELD shall be used for UAC prompts only, which is written at SIID_SHIELD description at MSDN.
See also
- StockIcons for Windows Presentation Framework? Yves Dolce
- Step 4: Redesign Your UI for UAC Compatibility MSDN
- and API documents SHSTOCKICONINFO and SHGetStockIconInfo() on MSDN