3

Is there any way to check the admin privileges in C#.Net Compact Framework??

I have the source code from MSDN in C++.

and

This will check if user is in the local Administrators group (assuming you're not checking for domain admin permissions):

using System.Security.Principal;

public bool IsUserAdministrator()
{
    //bool value to hold our return value
    bool isAdmin;
    try
    {
        //get the currently logged in user
        WindowsIdentity user = WindowsIdentity.GetCurrent();
        WindowsPrincipal principal = new WindowsPrincipal(user);
        isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
    }
    catch (UnauthorizedAccessException ex)
    {
        isAdmin = false;
    }
    catch (Exception ex)
    {
        isAdmin = false;
    }
    return isAdmin;
}

But using System.Security.Principal; is not available in C#.NET CF

Is it possible to implement the same in C#Net CF.

Oliver Matthews
  • 7,497
  • 3
  • 33
  • 36
arya2arya
  • 291
  • 2
  • 21
  • 1
    The main purpose of .Net Compact Framework is to target mobile platforms, so there are no admin privileges questions. Why are you using .Net CF here? – Nicolas R Jul 12 '14 at 21:12

0 Answers0