在节点 js 中使用管理员权限运行 exe

问题描述

我想以管理员身份使用 node.js 启动一个 exe 文件。尝试过这样的事情,但这不想工作:

exec('runas /user:Administrator "app.exe"',function(err,data) {  
                        console.log(err)                       
});

我总是收到这个错误Error: Command Failed: runas /user:Administrator "app.exe"

有什么想法吗?

解决方法

根据 runasdocumentation,您应该像这样包含 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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...