.NET Framework Bookmark and Share   
 index > Common Language Runtime > What namespace do i have to declare for my admin checking code?
 

What namespace do i have to declare for my admin checking code?

What do i have to do to prevent this code from giving me namespace errors?

bool IsAnAdministrator ()
{
WindowsIdentity identity =
WindowsIdentity.GetCurrent();
WindowsPrincipal principal =
new WindowsPrincipal (identity);
return principal.IsInRole
(WindowsBuiltInRole.Administrator);
}

WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();

WindowsPrincipal currentPrincipal = new WindowsPrincipal(currentIdentity);

System.AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

if (currentPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
{
MessageBox.Show("Is an Administrator "); }
else
{
MessageBox.Show(" Isn't Administrator ");
}
TheTrueFace
using System.Security.Principal;
using System.Windows.Forms;

Hans Passant.
  • Marked As Answer byTheTrueFace Thursday, September 17, 2009 5:05 AM
  •  
nobugz
using System.Security.Principal;
using System.Windows.Forms;

Hans Passant.
  • Marked As Answer byTheTrueFace Thursday, September 17, 2009 5:05 AM
  •  
nobugz

You can use google to search for other answers

Custom Search

More Threads

• Marshal unmanage pointer to array of structure
• Hash function performance
• problem in command-line utility
• Unhandled exception in .NET thread pool thread
• Best Practice for cross-thread marshalling of COM interop interfaces?
• Need help with StringBuilder and thread synchronization
• Obfuscators
• managed code execution quick question
• Can SafeFileHandle be used with BackupEventLog?
• ServiceController class internals