问题描述
我想以管理员身份使用 node.js 启动一个 exe 文件。尝试过这样的事情,但这不想工作:
exec('runas /user:Administrator "app.exe"',function(err,data) {
console.log(err)
});
我总是收到这个错误:Error: Command Failed: runas /user:Administrator "app.exe"
有什么想法吗?
解决方法
根据 runas
的 documentation,您应该像这样包含 ComputerName:
If you want to use the Administrator account on your computer,for the /user: parameter,type one of the following:
**/user:<**AdministratorAccountName>@<ComputerName>
**/user:<ComputerName>\<**AdministratorAccountName> <----- here