Skip to content Skip to sidebar Skip to footer

How To Know If Node-webkit App Is Running With Administrator/elevated Privilege?

How to determine if node-webkit is running with administrator privilege on Windows?

Solution 1:

Don't use npm packages for any small task - this is very bad practice.

var isElevated;

    try {
        child_process.execFileSync( "net", ["session"], { "stdio": "ignore" } );

        isElevated = true;
    }
    catch ( e ) {
        isElevated = false;
    }

Solution 2:

On windows, you can use the npm package is-admin, to check if the node process is elevated.

const isAdmin = require('is-admin');

isAdmin().then(elevated => {
    if (elevated) {
        console.log('Elevated');
    } else {
        console.log('Not elevated');
    }
});

There is also a cross platform implementation called is-elevated which bundles elevation checks for Unix and Windows

Solution 3:

Using the node-windows module, you can call the following function to determine whether the current user has admin rights:

var wincmd = require('node-windows');

wincmd.isAdminUser(function(isAdmin){
  if (isAdmin) {
    console.log('The user has administrative privileges.');
  } else {
    console.log('NOT AN ADMIN');
  }
});

Post a Comment for "How To Know If Node-webkit App Is Running With Administrator/elevated Privilege?"