All files / src/sso uac.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231x                               1x 4x 4x 4x 4x    
import { sspi } from '..';
 
/**
 * Test if the current user token has admin privileges.
 *
 * If this function return false, it means that operations that
 * requires admin rights cannot be done, even if the account is
 * configured with admin right. Functions that require admin right
 * would return the error 5 (admin right required).
 *
 * Example: `netapi.NetUserAdd` function can be called only
 * if the user token has admin privilege.
 *
 * @export
 * @returns {boolean}
 */
export function hasAdminPrivileges(): boolean {
  const sid = sspi.AllocateAndInitializeSid();
  const result = sspi.CheckTokenMembership(sid);
  sspi.FreeSid(sid);
  return result;
}