public static bool ChangeProcessPrivilege(Process process, string privilege, bool enable)
 {
     SafeTokenHandle handle;
     if (!OpenProcessToken(process.Handle, TOKEN.TOKEN_ADJUST_PRIVILEGES | TOKEN.TOKEN_QUERY, out handle))
     {
         return false;
     }
     try
     {
         LUID lpLuid = new LUID();
         if (!LookupPrivilegeValue(null, privilege, out lpLuid))
         {
             return false;
         }
         TOKEN_PRIVILEGES newState = new TOKEN_PRIVILEGES {
             PrivilegeCount = 1,
             Privileges = new LUID_AND_ATTRIBUTES[1]
         };
         newState.Privileges[0].Luid = lpLuid;
         newState.Privileges[0].Attributes = enable ? 2 : 0;
         if (!AdjustTokenPrivileges(handle, false, ref newState, (uint) Marshal.SizeOf(newState), IntPtr.Zero, IntPtr.Zero))
         {
             return false;
         }
     }
     finally
     {
         handle.Close();
     }
     return true;
 }
Exemple #2
0
 public Luid(LUID luid)
 {
     _luid = luid;
 }
		public static extern BOOL LookupPrivilegeValue(string lpSystemName, string lpName, out LUID Luid);
 public static extern bool LookupPrivilegeValue([MarshalAs(UnmanagedType.LPTStr)] string lpSystemName, [MarshalAs(UnmanagedType.LPTStr)] string lpName, out LUID lpLuid);