I have a Powershell command I can run normally and it will execute an HTA application on a remote server if I run it from powershell it works with 0 issues. When I try to invoke the same command via shell_exec
in php the application launches as I can see it interactively but the arguments are being passed without quotes which the hta will not recognize. I need help figuring out how to pass the quotes around the variables as well.
Also I have -NoExit
inserted for troubleshooting purposes so the powershell window doesn't close.
Another note when I echo out $runCMD2;
Its perfectly formatted as if I were going to copy and paste it into a powershell window
The following PHP Code launches the window but does not pass the 2 arguments:
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";
}
The answer was I needed to add 8 quotes on each side as such! Totally found the answer after posting this question.
$msiName = '"""""""""MSI_test_name_goes_here"""""""""';
$installDir = '"""""""""D:\\some\\needed\\path\\"""""""""';