运行 来自 PHP 的 PowerShell 命令使用参数执行 HTA

Running PowerShell Command from PHP to Execute HTA with Arguments

我有一个 Powershell 命令,我可以正常 运行 如果我从 powershell 运行 它会在远程服务器上执行一个 HTA 应用程序,它可以处理 0 个问题。当我尝试通过 php 中的 shell_exec 调用相同的命令时,应用程序启动,正如我可以交互看到的那样,但传递的参数没有引号,hta 无法识别。我需要帮助弄清楚如何在变量周围传递引号。

我还插入了 -NoExit 用于故障排除,因此 powershell window 不会关闭。

当我回显时的另一个注释 $runCMD2; 它的格式非常完美,就好像我要将它复制并粘贴到 powershell 中一样 window

以下 PHP 代码启动 window 但不传递 2 个参数:


    function buildPackage()
                    {
                        $serverName = "\\server";
                        $msiName = '"MSI_test_name_goes_here"';
                        $installDir = '"D:\some\needed\path\"';

                        $runCMD2 = 'start powershell.exe -NoExit psexec -accepteula -s -i 2 '.$serverName.' cmd /c D:\path\to\my.hta '.$msiName.' '.$installDir;
                        echo $runCMD2;
                        $execCMD = shell_exec("$runCMD2");
                        //Begin Building
                        echo "Starting Build...<br>";
                        echo $execCMD;
                        echo "Build Complete";

                    }

答案是我需要在每边添加 8 个引号!发布这个问题后完全找到了答案。


$msiName = '"""""""""MSI_test_name_goes_here"""""""""';
$installDir = '"""""""""D:\some\needed\path\"""""""""';