note 83850 added to function.exec

From: Date: Sun, 15 Jun 2008 06:09:37 +0000
Subject: note 83850 added to function.exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-140454@lists.php.net to get a copy of this message
Task: Invoke psexec from php to execute a command on a remote computer. Environment: -Windows XP Professional, Service Pack 3 -Apache 2.2 Installed (I used the version bundled in XAMP 1.6.6a) -The executable to be run must be in your system PATH!! PHP Script: <?php exec ("psexec -u someusername -p somepassword -c \\\\someipaddressORHostname someprogram.exe"); #sample command #exec ("psexec -u JoeShmoe -p ShrimpLover529 -c \\\\192.168.22.156 cleanfiles.exe"); ?> Problems: -I kept getting Access Denied Errors Observation(s): -I noticed that when I put that same psexec command in a batch file and started that batch file with the system account, I would get the same error -This lead me to the cause Cause: -Apache was running as the system account, and so any process invoked by php was started as the system account -Starting a batch file that accesses a remote computer using the local system account is a NO NO (at least for my setup) Solution: -Configure the Apache service to start as an account other than system (It must have appropriate permissions on the local computer) Start-->Run-->Services.msc-->RightClick Apache Service-->Properties-->Logon Tab-->Enter in value for "Log on As" Now load the same php page again. Look at the error.log again You should see an error code 0 returned for the process executed, indicating a successful run ---- Server IP: 217.160.72.57 Probable Submitter: 209.235.223.85 ---- Manual Page -- http://www.php.net/manual/en/function.exec.php Edit -- https://master.php.net/note/edit/83850 Del: integrated -- https://master.php.net/note/delete/83850/integrated Del: useless -- https://master.php.net/note/delete/83850/useless Del: bad code -- https://master.php.net/note/delete/83850/bad+code Del: spam -- https://master.php.net/note/delete/83850/spam Del: non-english -- https://master.php.net/note/delete/83850/non-english Del: in docs -- https://master.php.net/note/delete/83850/in+docs Del: other reasons-- https://master.php.net/note/delete/83850 Reject -- https://master.php.net/note/reject/83850 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140454) next »