Пример #1
0
      private void AdjustPrivilege(bool enable)
      {
         using (WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent(TokenAccessLevels.Query | TokenAccessLevels.AdjustPrivileges))
         {
            if (currentIdentity != null)
            {
               IntPtr hToken = currentIdentity.Token;
               TokenPrivileges newPrivilege = new TokenPrivileges();
               TokenPrivileges mOldPrivilege = new TokenPrivileges();
               newPrivilege.PrivilegeCount = 1;
               newPrivilege.Luid = Filesystem.NativeMethods.LongToLuid(_mPrivilege.LookupLuid());
               newPrivilege.Attributes = (uint)(enable ? 2 : 0);    // 2 = SePrivilegeEnabled;

               uint length;
               if (!NativeMethods.AdjustTokenPrivileges(hToken, false, ref newPrivilege, (uint) Marshal.SizeOf(mOldPrivilege), out mOldPrivilege, out length))
                  NativeError.ThrowException(Marshal.GetLastWin32Error());

               // If no privilege was changed, we don't want to reset it.
               if (mOldPrivilege.PrivilegeCount == 0)
                  _mPrivilege = null;
            }
         }
      }
Пример #2
0
 internal static extern bool AdjustTokenPrivileges(IntPtr tokenHandle, [MarshalAs(UnmanagedType.Bool)] bool disableAllPrivileges, ref TokenPrivileges newState, uint bufferLength, out TokenPrivileges previousState, out uint returnLength);
Пример #3
0
 internal static extern bool AdjustTokenPrivileges(IntPtr tokenHandle, [MarshalAs(UnmanagedType.Bool)] bool disableAllPrivileges, ref TokenPrivileges newState, uint bufferLength, out TokenPrivileges previousState, out uint returnLength);