internal static LUID GetLUID(SystemPrivilege systemPrivilege, string systemName = null) { LUID val; lock (luidLookup) { if (!luidLookup.TryGetValue(systemPrivilege, out val)) { val = LUID.FromName(PrivLookup[systemPrivilege], systemName); luidLookup.Add(systemPrivilege, val); } } return(val); }
public ElevPriv(string priv, HPROCESS hProc = default, TokenAccess access = TokenAccess.TOKEN_ADJUST_PRIVILEGES | TokenAccess.TOKEN_QUERY) { if (hProc.IsNull) { hProc = GetCurrentProcess(); } tok = SafeHTOKEN.FromProcess(hProc, access); var newPriv = new PTOKEN_PRIVILEGES(LUID.FromName(priv), PrivilegeAttributes.SE_PRIVILEGE_ENABLED); prevState = PTOKEN_PRIVILEGES.GetAllocatedAndEmptyInstance(); if (!AdjustTokenPrivileges(tok, false, newPriv, (uint)prevState.Size, prevState, out var retLen)) { Win32Error.ThrowLastError(); } prevState.Size = (int)retLen; }
private void ElevatePrivileges(string[] privs) { var newPriv = new PTOKEN_PRIVILEGES(Array.ConvertAll(privs, s => new LUID_AND_ATTRIBUTES(LUID.FromName(s), PrivilegeAttributes.SE_PRIVILEGE_ENABLED))); prevState = PTOKEN_PRIVILEGES.GetAllocatedAndEmptyInstance(); if (!AdjustTokenPrivileges(tok, false, newPriv, prevState.Size, prevState, out var retLen)) { Win32Error.ThrowLastError(); } prevState.Size = (int)retLen; }
private void ElevatePrivileges(string[] privs) { var newPriv = new TOKEN_PRIVILEGES(Array.ConvertAll(privs, s => new LUID_AND_ATTRIBUTES(LUID.FromName(s), PrivilegeAttributes.SE_PRIVILEGE_ENABLED))); AdjustTokenPrivileges(tok, false, newPriv, out prevState).ThrowIfFailed(); }