views:

154

answers:

2

Hi All, 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?

+1  A: 

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.

Ólafur Waage
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?
Ali Bozorgkhan
if you have the correct error level
Ólafur Waage
I checked the php.ini file and the safe_mode is off. disable_functions is empty.
Ali Bozorgkhan
+1  A: 

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).

Yannick M.
Is it possible to test this remotely from another computer? I don't have access to the pc right now.
Ali Bozorgkhan
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.
Yannick M.
I'm having problem with php exec function. You sure this is related to exec?
Ali Bozorgkhan
`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.
Yannick M.
I checked echo system("dir"); and it echoed 'system("dir")' ! not a directory listing of the current folder.
Ali Bozorgkhan
Are you sure you aren't doing `echo 'system("dir")';`?
Yannick M.