PHP命令以admin身份执行powershell脚本

时间:2018-03-29 18:14:59

标签: php powershell xampp

我想从PHP以管理员身份运行PowerShell脚本。我使用下面的命令来运行脚本,但它不会以管理员身份执行。

任何帮助如何使这个工作? 我使用的是旧版XAMP。

$output=shell_exec('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command E:\XAMPP_DV\htdocs\project\lib\pwdreset.ps1 ' . $user . " " . $pwd);

2 个答案:

答案 0 :(得分:0)

我要走出困境并假设你没有正确设置政策:

$output = shell_exec('powershell -ExecutionPolicy Bypass -NoProfile -File "E:\XAMPP_DV\htdocs\project\lib\pwdreset.ps1" ' . $user . ' ' . $pwd);

在几乎所有情况下,powershell.exe的路径都在PATH环境变量中,默认情况下ExecutionPolicy设置为RemoteSigned

答案 1 :(得分:0)

Microsoft TechNet建议以下解决方案

$output=shell_exec('powershell -noprofile -command "&{ start-process powershell -ArgumentList -noprofile -file E:\XAMPP_DV\htdocs\project\lib\pwdreset.ps1 ' . $user . ' ' . $pwd . ' -verb RunAs}"');
相关问题