Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在提升powershell中执行命令_Node.js_Powershell - Fatal编程技术网

Node.js 在提升powershell中执行命令

Node.js 在提升powershell中执行命令,node.js,powershell,Node.js,Powershell,我正在运行Node.JS应用程序,该应用程序正在执行一些powershell命令,以便为我的WiFi接口设置DNS服务 不幸的是,脚本在没有管理员权限的情况下失败,因此我尝试在node.js中提升脚本 Start-Process -FilePath powershell.exe -ArgumentList { Write-Host "Hello" Set-DnsClientServerAddress -InterfaceIndex 10 -ServerAddres

我正在运行Node.JS应用程序,该应用程序正在执行一些powershell命令,以便为我的WiFi接口设置DNS服务

不幸的是,脚本在没有管理员权限的情况下失败,因此我尝试在node.js中提升脚本

Start-Process -FilePath powershell.exe -ArgumentList {
   Write-Host "Hello"
   Set-DnsClientServerAddress -InterfaceIndex 10 -ServerAddresses ("127.0.0.1", "8.8.8.8")
   sleep 5
} -verb RunAs

出于某种原因,尽管脚本输出“hello”并等待5秒钟,但这并没有应用更改。有人知道为什么会这样吗?

-PassThru
添加到
设置DnsClientServerAddress
中,并检查接口的状态输出。再次检查您是否仍然拥有正确的
接口索引
(据说,我的电脑使用vpn伪接口时表现异常)。将
-Verbose
添加到
设置DnsClientServerAddress
中,并查看它是否添加了任何有用的输出。@Zilog80它记录旧服务器addresses@Cpt.Whale
VERBOSE:将根据请求更改Microsoft DNS客户端设置。这将影响适配器“WiFi”上的名称解析
日志,但它仍然不会更改。我仔细检查了正确的接口indexIt,听起来好像它正在运行,也许可以尝试使用
-ServerAddresses 127.0.0.1,8.8.8.8
,而不使用引号或括号。您是否将dns设置设置回脚本中的任何位置?