Salient Solutions

wrasslin ones and nones for fun and profit - Sky Sanders' Blog
posts - 96, comments - 70, trackbacks - 0

Adding/Removing UAC Shield to button

  #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: , ,

Print | posted on Thursday, January 07, 2010 3:43 AM | Filed Under [ CodeProject-Tip ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 5 and type the answer here:

Powered by: