npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

win32-privileges

v2.0.0

Published

Determine user privileges in Windows

Downloads

83

Readme

win32-privileges

A lightweight Node.js library for inspecting Windows privileges for the current process using native Windows APIs.


Motivation

The privilege model for Windows differs quite a bit from that of Unix: Where in Unix there is a root user for elevation, the Windows security API relies on certain privileges afforded to users:

privilege

The right of a user to perform various system-related operations, such as shutting down the system, loading device drivers, or changing the system time. A user's access token contains a list of the privileges held by either the user or the user's groups.

While Node offers a way to determine if running with elevated privileges in Unix, there is no way on Windows to check whether a process is elevated, much less what specific privileges it has. This library closes that gap.


Installation

npm install win32-privileges

For obvious reasons, this library only works on Windows. Package managers will refuse installation on other platforms, and calling it will throw an error.

If you are developing a cross-platform project, you should define it as an optional dependency:

npm install --save-optional win32-privileges

Usage

import { getPrivileges } from 'win32-privileges';

const privileges = getPrivileges();

for (const privilege of privileges) {
  console.log(privilege.name, privilege.isEnabled());
}

API

getPrivileges(): Privilege[]

Retrieves all privileges associated with the current process token, regardless of whether they are enabled or not. A privilege that is present but disabled is potentially available to this process, i.e. within the scope of permitted operations for the user owning the process. Only enabled privileges, however, actually entitle the process to carry out the associated operations.

For example, a process may have the SE_SHUTDOWN_PRIVILEGE privilege present. This means that it can potentially shut down the system, but it cannot do so currently (because the privilege is disabled). To actually shut down the system, the process requires an enabled SE_SHUTDOWN_PRIVILEGE. If the privilege is not present at all, the process can never shut down the system.

Use getEnabledPrivileges if you want to get a list of enabled privileges.

Returns {Privilege[]} An array of Privilege objects representing all privileges assigned to the current process.

Throws Error If called on platform other than Windows.

hasPrivilege(privilege: string): boolean

Checks whether the current process has a specific privilege assigned, regardless of whether the privilege is enabled or not.

See getPrivileges for details on present vs enabled privileges.

Use hasEnabledPrivilege instead if you want to check for enabled privileges.

Parameters

  • string privilege - The name of the privilege to check.

Returns boolean true if the privilege exists in the process token; otherwise false.

Throws Error If called on platform other than Windows.

getEnabledPrivileges(): Privilege[]

Retrieves all enabled privileges associated with the current process token. These privileges are active, i.e. entitle the process to carry out the associated operations.

See getPrivileges for details on present vs enabled privileges.

Returns Privilege[] An array of enabled Privilege objects.

Throws Error If called on platform other than Windows.

hasEnabledPrivilege(privilege: string): boolean

Checks whether a specific privilege is present and enabled for the current process.

See getPrivileges for details on present vs enabled privileges.

Parameters

  • string privilege - The name of the privilege to check.

Returns boolean true if the privilege exists in the process token and is enabled; otherwise false.

Throws Error If called on platform other than Windows.

Class Privilege

Represents a single privilege.

A privilege is the right of a user to perform various system-related operations, such as shutting down the system, loading device drivers, or changing the system time. A user's access token contains a list of the privileges held by either the user or the user's groups. These privileges are inherited by processes owned by the user.

A Privilege consists of the privilege's name, and its activation status.

This class exposes all privilege names as static properties, while dropping the _NAME suffix (so e.g. Privilege.SE_CREATE_TOKEN).

Properties

  • string name The name of this privilege. This is the value of one of the privilege name constants.

Methods

isEnabled(): boolean

Whether this privilege is currently enabled.

Only enabled privileges entitle the process to carry out the associated operations.

Returns boolean true is this privilege is enabled, false otherwise.

isEnabledByDefault(): boolean

Whether this privilege is enabled by default when the token is created.

A privilege that is enabled by default may still be disabled later.

Returns boolean true if this privilege is enabled by default, false otherwise.

wasUsedforAccess(): boolean

Whether this privilege has actually been used. (Specifically, whether it has contributed to at least one successful access check.)

Returns boolean true if this privilege has been used by the process, false otherwise.


How It Works

This library directly interfaces with the Windows API using a bridging mechanism called Foreign Function Interfaces (FFI). Specifically, it uses koffi, which comes pre-built for many platforms including Windows, so as to avoid a build step on install.