I have been reading about exec() and passthru() and system() and different ways to use these, but so far not one of them is working. The Closest I have gotten is to get a request from CMD printed up on the page and so I researched how to pass a password programmatically to PHP to fill in the password, but I haven't quite figured it out.

I have tried dozens of different ways to get any of the methods to work, but the closest I have come is with this:

echo exec('runas /user:<Computer>\<User> "notepad.exe"' );

I'm using notepad here becasue I want to learn how to start an executable from PHP and notepad seems like an easy starting place.

I found a vb script through my searches and it is supposed to be able to fill in passwords for the runas call, but I'm not sure how to call it using PHP so I decided to ask if anyone knows how to call a vb script from PHP and the method or syntax you would use?

Thank you for that advice, but I tried it and found out that my OS version (Windows 7 Home) doesn't allow piping values into runas. So, my question is the same as before still. One thing to note is that apparently PHP is starting the executable and it shows in task manager and it shows that it's running under the account I hard-coded into the vb-script (which is also the same user account I configured Apache to run under). I also configured Apache (though services.msc) to be able to interact with the desktop. My question now, I suppose, is why are these processes running in the background and why I get them to pop up for user use? Maybe I'm missing something like: do I have to configure something in PHP.ini or in httpd.ini for Apache to allow for executables to interface with users?

Here's how the code looks now and it starts the process, but as a background which cannot be accessed for some reason:

    //$results = array();
    //$results = exec('runas /user:Windows7-PC\James "notepad.exe"');
    $results = exec('Start C:\\xampp\\vbs_runas_script.vbs');
    echo $results; // prints out nothing
    echo "Done";  // prints out as soon as the background process begins
    // what am I missing? 

Since I don't have a windows box, unfortunately I cannot test and I'm realizing that runas never accepts pipes or redirections (with the pro edition, maybe, you could use the /savecred option), so excuse me for the wrong suggestion.

If the user that you have to call through runas is static, then you could change the apache user to the same one, or at least to the same group, so it should execute the script with the correct privileges. At that point you should be able to avoid runas.

Anyway, while waiting for more appropriate support from windows people, I can only think to try to serve the script as a windows service, so outside from an Apache instance, and use another script to send the input. Good luck!

I have tried adjusting the user and group using the httpd config file and using the Windows Services management console. Currently I can get PHP to run the executable,but every time I get a pop up from the Interactive Services Detection Service that tells me that a service has a message for me and that message is the running executable. I'm obviously missing some kind of configuration here. I don't even expect to find an answer on here because I searched this site's old posts and found 3 or 4 other posts exactly like this and none had a good answer or a solution for the OP--and the PHP manuals don't have any either. Does anyone have any advice for getting past the Interactive Services Detection pop-up?

I don't know anything about vbs but I did manage to find an answer just by doing a bit of digging (http://www.php.net/manual/en/function.exec.php)

If you use the format:

exec('start /B "my_window" "vbs/hello.vbs"',$output,$return);

Then it opens the VBS in the background. My VBS program was just a MsgBox. If you want to open a proper window from the VBS or capture the output (try sleep in the PHP program), then you will probably have some further challenges that will require a bit of research / experimentation.

Once again, thank you for the advice, but as one of the posts above states, I have studied the PHP manuals and multiple other sources and do have PHP executing an executable already, but what is happening is that the Windows Interactive Services Detection Service pops up every time and the executable is the message it shows me when I click on 'view the message'. Here is my configurations: In Services.msc I have Apache running on: Local System Account and I have allowed it to interact with the desktop.

Here are some of the lines of code which (all) end up with a forced Interactive Services Interaction:

As you can see, I have gotten exec(), system() and passthru() to work, but all end up with the same problem. The problem is that the executable won't pop up to the desktop, but instead the Interactive Services Detection pops up. If I disable this service then nothing pops up. What I want to know is if anyone can tell me how to get PHP to execute a program on Windows in the foreground and not the background? I have been doing some more researching and think it might have something to do with Apache being installed as a service--any advice on that?

//exec('notepad.exe');
//system('Psexec.exe -i -d notepad.exe');
//exec("Psexec.exe -i -d  notepad.exe");
//passthru("notepad.exe", $results);

Ok, I have solved the problem. Thanks to everyone who offered advice, but I had to solve it myself (and that is always the best way isn't it?). If you run into the problem I had where you're running Windows and Apache and PHP then you can solve the problem of PHP executing executables being blocked by the Interactive Services Detection pop up (and run in the background as session 0 or whatever) you can solve the issue by uninstalling Apache as a service and running it as an app under an administrator's account. I don't know what implications this has on security, but I can tell you that if you run it as an app under an admin you will be able to run executables from within PHP scripts. Once again thank you to everyone for your helpful hints, but I guess this problem is one that you can only solve by being there and putting in enough research.

One important note is that if you are running Apache and PHP under Xampp then you can uninstall Apache as a service by just unchecking the green checkmark next to Apache on the Xampp control panel. Thanks to everyone again.

commented: thanks for sharing your solution +11
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.