I am running PHP under IIS 6.
When I use any PHP function to run cmd commands (like exec()
or system()
), it always shows "Access is denied".
Even commands like ipconfig
are showing same "access is denied" error. I have given all the permission to my project folder but it did not work.
Please let me know anyone the cause of it.
When you execute some command using
exec
, that command will be executed with the user account that is running IIS (which tipically isIUSR_«machine-name»
on IIS 6), so your project's permissions don't have nothing to do with this.What you need to do is to chance the permissions of the file
C:\Windows\System32\cmd.exe
and add permissions forIUSR_«machine-name»
.Besides this, you'll probably need to use CACLS to change the access control list. Replace
IUSR_MachineName
on the following command for the user executing PHP and then execute this command:If you get an error and can't change the ACL, your last resource is to execute the following command first:
You also might need to set the correct permissions and ACL for the commands you're trying to execute (for eg
C:\Windows\System32\schtasks.exe
)Note: Do this with caution though. If you have some vulnerability that allows your users to execute commands, it can have nasty consequences.