Ejemplo n.º 1
0
        public static bool SetPrivilege(string privilege, bool enabled = true)
        {
            IntPtr tokenHandle;

            Process32.LUID luid;
            if (Process32.OpenProcessToken(Process32.GetCurrentProcess(), Process32.TOKEN_ADJUST_PRIVILEGES | Process32.TOKEN_QUERY, out tokenHandle) && Process32.LookupPrivilegeValue(null, privilege, out luid))
            {
                Process32.TOKEN_PRIVILEGES tOKEN_PRIVILEGES;
                tOKEN_PRIVILEGES.PrivilegeCount = 1u;
                tOKEN_PRIVILEGES.Luid           = luid;
                tOKEN_PRIVILEGES.Attributes     = 2u;
                return(Process32.AdjustTokenPrivileges(tokenHandle, false, ref tOKEN_PRIVILEGES, 1024, IntPtr.Zero, IntPtr.Zero));
            }
            return(false);
        }