3

I am trying to run this:

shell_exec("powershell -File C:\inetpub\wwwroot\altirisinstall\startinstall.ps1 $computername > /dev/null &");

It works fine as long as I remove:

/dev/null &

However, that makes the website pause and wait for the script to finish. When I have that included, the script never runs.

I have also tried this and it stops the ps1 from running as well:

/dev/null 2>&1 &

Edit: I need a way to have my php run a powershell script on a windows server and not wait for the response. Waiting causes my website to hang and prevents the users from running a new command. I researched and found the above solutions, but someone has pointed out that those are for linux servers. Is there another way to execute my powershell script and not wait for a response?

Edit2: I can't get the powershell to launch at all now, the sql command runs fine and the page refreshes, but the powershell never runs, here is the code:

<?php
if(isset($_POST['Submit'])) {
    $connectionInfo = array( "Database"=>"database", "UID"=>"username", "PWD"=>"password");
    $conn = sqlsrv_connect( "server", $connectionInfo);
    $params = array();
    $username = $_SERVER['AUTH_USER'];
    $computername = $_POST['CName'];
    $time = date("m/d - g:i a");
    $sql2 = "INSERT INTO dbo.Installs (Hostname, Status, Username, Time) VALUES (?, ?, ?, ?)";
    $var = array($computername, "InProgress", $username, $time);
    sqlsrv_query($conn, $sql2, $var);
    sqlsrv_close($conn);

    shell_exec("powershell.exe -File C:\inetpub\wwwroot\altirisinstall\startinstall.ps1 $computername");
    sleep(5);

    header("Refresh:0");
}
?>
Jack
  • 31
  • 5

1 Answers1

0

There is no solution for this problem. This is a security measure in IIS that I don't want to spend the time trying to go around. I have gone a different route for this, Thanks for all the help.

Jack
  • 31
  • 5