How to know if node-webkit app is running with Administrator/elevated privilege?

一世执手 提交于 2019-12-11 12:03:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!