2

I'm running a php script through the webserver to execute psexec which in turns executes another php script.

When I run this from the command line normally, everything works fine and there are no problems.

However, when I run it from the webserver, I get this:

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

php exited with error code 1.

So from this I can obviously tell that psexec is running properly, but for some reason the php script is exiting. Like I said, though, if I run it manually from the command line, it works perfectly.

I tried to do a bit of looking around, but I can't figure it out. Does anyone know?

I'm running Apache2 (XAMPP) on Windows 2008

Rob
  • 2,393
  • 9
  • 33
  • 52

1 Answers1

0

Error codes returned by PsExec are specific to the applications you execute, not PsExec. If psexec successfully connects and runs the target program it will return the errorlevel from that program. 0 is usually success, 1 is usually incorrect/invalid/fail.

What are you trying to accomplish? Maybe you can setup a scheduled task to run the script or some other method of launching it. Maybe the service account running apache does not have execute permissions on the script?

EDIT: also try adding the -accepteula flag to the psexec command in your PHP code. It may be getting hung on accepting the EULA

iainlbc
  • 2,694
  • 19
  • 19
  • How would I go about giving it execute permissions, or even finding out which account is running apache? – Rob Oct 07 '11 at 19:24
  • Task manager, show processes from all users. Then Right click the script > properties > security/permissions and add give that account full control. – iainlbc Oct 07 '11 at 19:27
  • I had the accepteula problem prior to this, but another helpful user helped me solve that. I'll look into the execution permissions – Rob Oct 07 '11 at 19:29
  • It's also possible apache account doesn't have permissions to execute psexec. Can you launch something else like Notepad from your php code? relevant, you might want to try this registry modification (2nd post from bottom): http://forum.sysinternals.com/problems-with-psexec-and-php_topic24670.html – iainlbc Oct 07 '11 at 19:32
  • As for your first idea: `http://img843.imageshack.us/img843/7480/ss20111007153532.png` apache does seem to have permissions to execute everything. The PHP script seems to execute psexec just fine, but then psexec gets an error code from the php script that psexec executes. (Hope you could follow all that, it got a bit repetitive) – Rob Oct 07 '11 at 19:37
  • I'll check that reg modification right now – Rob Oct 07 '11 at 19:37
  • Alright, I tried that, and still I have the same problem. – Rob Oct 07 '11 at 19:58
  • So this is the order? php > psexec > php . And it works fine when you do just psexec > php. Can you please try giving "Everyone" Full Control of psexec.exe, and the last php script that is being executed. Can you add in a line of code to the top of the last php script to create a blank file, C:/text.txt for instance, to see psexec ix capable of executing the first line of code? Is there anything in logs or event viewer? – iainlbc Oct 07 '11 at 21:02
  • Did you get this resolved Rob? – iainlbc Oct 14 '11 at 18:31