public static bool HasPrivileges(this AdvApi32.SafeTokenHandle hObj, bool requireAll, params SystemPrivilege[] privs) { bool ret; if (!AdvApi32.PrivilegeCheck(hObj, new AdvApi32.PRIVILEGE_SET((AdvApi32.PrivilegeSetControl)(requireAll ? 1 : 0), privs.Select(p => new AdvApi32.LUID_AND_ATTRIBUTES(p.GetLUID(), AdvApi32.PrivilegeAttributes.SE_PRIVILEGE_ENABLED)).ToArray()), out ret)) { throw new Win32Exception(); } return(ret); }