Check WIN NT Permissons

Results 1 to 2 of 2

Thread: Check WIN NT Permissons

  1. #1
    Join Date
    Dec 1969

    Default Check WIN NT Permissons

    How do I check if a user is an administrator on their machine?

  2. #2
    Join Date
    Dec 1969

    Default RE: Check WIN NT Permissons

    Check your email and there should be a zip file that does this? Also you could try something like this!<BR><BR>try<BR>{<BR><BR>//By default deny access to the C Drive.....<BR>CodeAccessPermission UserPermission = new FileIOPermission(FileIOPermissionAccess.AllAccess, @"c:\");<BR><BR>//Check whether the user is part of the administrator group<BR>AppDomain.CurrentDomain.SetPrincipalPolic y(PrincipalPolicy.WindowsPrincipal);<BR>WindowsPri ncipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;<BR>Wind owsIdentity identity = (WindowsIdentity)principal.Identity;<BR><BR>bIsAdm in = principal.IsInRole(WindowsBuiltInRole.Administrato r);<BR><BR>//Its not, so deny access to the file<BR>if(!bIsAdmin)<BR>{<BR>UserPermission.Deny( );<BR>}<BR>else<BR>{<BR>//Do the read<BR>din = ReadTheFile.DoTheRead(); <BR>}<BR><BR>if(!bIsAdmin)<BR>{<BR>//Reset deny permissions in current stack frame<BR>CodeAccessPermission.RevertDeny();<BR>}<B R><BR>//If we got this far .... we read in the file<BR>String str;<BR><BR>while ((str=din.ReadLine()) != null) <BR>{<BR>listBox1.Items.Add(str);<BR>}<BR>}<BR>cat ch (SecurityException exception)<BR>{<BR>//Failed to pass the security checks - so flag up error to user <BR>listBox1.Items.Add("Permission denied accessing file");<BR>}<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts