#region UAC
private const int BcmFirst = 0x1600; //Normal button
private const int BcmSetshield = (BcmFirst + 0x000C); //Elevated button
[DllImport("user32")]
private static extern UInt32 SendMessage(IntPtr hWnd, UInt32 msg, UInt32 wParam, UInt32 lParam);
private static void AddShieldToButton(Button b)
{
b.FlatStyle = FlatStyle.System;
SendMessage(b.Handle, BcmSetshield, 0, 0xFFFFFFFF);
}
private static void RemoveShieldFromButton(Button b)
{
b.FlatStyle = FlatStyle.System;
SendMessage(b.Handle, BcmSetshield, 0, 0x0);
}
private static bool IsAdmin()
{
WindowsIdentity id = WindowsIdentity.GetCurrent();
WindowsPrincipal p = new WindowsPrincipal(id);
return p.IsInRole(WindowsBuiltInRole.Administrator);
}
#endregion
Technorati tags:
C-Sharp,
UAC,
CodeProject-Tip