[英]How to know if node-webkit app is running with Administrator/elevated privilege?
如何确定 node-webkit 是否在 Windows 上以管理员权限运行?
On windows, you can use the npm package is-admin , to check if the node process is elevated.在 Windows 上,您可以使用 npm 包is-admin来检查节点进程是否已提升。
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还有一个名为is-elevated的跨平台实现,它捆绑了 Unix 和 Windows 的海拔检查
Don't use npm packages for any small task - this is very bad practice.不要将 npm 包用于任何小任务 - 这是非常糟糕的做法。
var isElevated;
try {
child_process.execFileSync( "net", ["session"], { "stdio": "ignore" } );
isElevated = true;
}
catch ( e ) {
isElevated = false;
}
Using the node-windows module, you can call the following function to determine whether the current user has admin rights:使用node-windows模块,您可以调用以下函数来确定当前用户是否具有管理员权限:
var wincmd = require('node-windows');
wincmd.isAdminUser(function(isAdmin){
if (isAdmin) {
console.log('The user has administrative privileges.');
} else {
console.log('NOT AN ADMIN');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.