0

I developed a program on windows xp and I used exec to run a ".bat" file and it worked fine. I copied the exact program on windows 2003 and the bat file didn't run. I used echo before the exec function and it seemed to work fine, I mean it echoed :

D:\xampp\htdocs\x>RunDLL32.EXE printui.dll,PrintUIEntry /y /n "HP LaserJet P2015 Series PS"

but it didn't do anything. I ran the bat file alone and it worked fine. Just doesn't work with exec in windows 2003. any ideas?

2 Answers 2

1

Is safe mode enabled on that server? If so then you won't be able to execute programs like that. You either need to turn safe mode off or add that directory to the safe_mode_exec_dir in PHP.ini

From the manual

Note: When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanx for your reply, I don't have access to that pc but i will check the safe mode ASAP. If the safe mode is on, Shouldn't I give a warning or something for calling exec?
I checked the php.ini file and the safe_mode is off. disable_functions is empty.
1

If you are using IIS, in order to execute an application the Internet Guest account needs execute rights on CMD.exe. As every shell execute is run as CMD.exe -c <your command>.

Then verify that a simple echo system("dir"); works. This should return the directory listing of the current folder.

It is also likely you will have to give the Internet Guest account execute rights to the batch file, and any executable it executes (in this case rundll32.exe).

6 Comments

Is it possible to test this remotely from another computer? I don't have access to the pc right now.
Yes to verify that you have execute rights on cmd.exe check echo system("dir");. If this works, verify that executing a batch file with only dir in it works. From there you can assert that the rundll32.exe is the problem.
I'm having problem with php exec function. You sure this is related to exec?
exec, passthru and system all work in more or less the same way. exec returns the stdout in a array of strings, system returns the stdout as a string, and passthru is used when the executing program returns binary data which needs to be captured in its raw form. So yes, if either work, all should work.
I checked echo system("dir"); and it echoed 'system("dir")' ! not a directory listing of the current folder.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.