Beispiel #1
0
 public static bool DisablePrivilege(string privilege)
 {
     try
     {
         int             token  = 0;
         int             retVal = 0;
         TOKEN_PRIVILEGE TP     = new TOKEN_PRIVILEGE();
         LUID            LD     = new LUID();
         retVal            = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref token);
         retVal            = LookupPrivilegeValue(null, privilege, ref LD);
         TP.PrivilegeCount = 1;
         // TP.Attributes should be none (not set) to disable privilege
         var luidAndAtt = new LUID_AND_ATTRIBUTES();
         luidAndAtt.Luid = LD;
         TP.Privilege    = luidAndAtt;
         retVal          = AdjustTokenPrivileges(token, 0, ref TP, 1024, 0, 0);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #2
0
 public static bool DisablePrivilege(string privilege)
 {
     try
     {
         int token = 0;
         int retVal = 0;
         TOKEN_PRIVILEGE TP = new TOKEN_PRIVILEGE();
         LUID LD = new LUID();
         retVal = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref token);
         retVal = LookupPrivilegeValue(null, privilege, ref LD);
         TP.PrivilegeCount = 1;
         // TP.Attributes should be none (not set) to disable privilege
         var luidAndAtt = new LUID_AND_ATTRIBUTES();
         luidAndAtt.Luid = LD;
         TP.Privilege = luidAndAtt;
         retVal = AdjustTokenPrivileges(token, 0, ref TP, 1024, 0, 0);
         return true;
     }
     catch
     {
         return false;
     }
 }
Beispiel #3
0
 public static extern int AdjustTokenPrivileges(int tokenhandle, int disableprivs,
                                                [MarshalAs(UnmanagedType.Struct)] ref TOKEN_PRIVILEGE Newstate, int bufferlength,
                                                int PreivousState, int Returnlength);