//////////////////////////////////////////////////////////////////////////////// // Enables, Disables, or Removes a privilege from a Token //////////////////////////////////////////////////////////////////////////////// private static void _AlterPrivilege(CommandLineParsing cLP, IntPtr hToken, Winnt.TokenPrivileges attribute) { using (TokenManipulation t = new TokenManipulation(hToken)) { if (cLP.Remote && !cLP.Impersonation && t.OpenProcessToken(cLP.ProcessID)) { t.SetWorkingTokenToRemote(); } else if (cLP.Remote && cLP.Impersonation) { t.ListThreads(cLP.ProcessID); t.SetThreadTokenPrivilege(cLP.Privilege, attribute); } else if (!cLP.Remote && cLP.Impersonation) { t.ListThreads(Process.GetCurrentProcess().Id); t.SetThreadTokenPrivilege(cLP.Privilege, attribute); } else { t.SetWorkingTokenToSelf(); } t.SetTokenPrivilege(cLP.Privilege, attribute); } }