问题
How to determine if node-webkit is running with administrator privilege on Windows?
回答1:
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
回答2:
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');
}
});
来源:https://stackoverflow.com/questions/29669244/how-to-know-if-node-webkit-app-is-running-with-administrator-elevated-privilege