Jump to content

Error When Trying To Execute The Shell_exec() Command


ready2drum
 Share

Recommended Posts

I'm having trouble resolving an error that involves PHP and some Visual Basic script....The code below is supposed to search for a specific file on the network and then close it if the file is open. However, when I click on the link to invoke the request, I get the following error message:----Warning: shell_exec() [function.shell-exec]: Unable to execute 'net file | Find /i "Millweek.pdf"' in E:\Inetpub\wwwroot\Intranet_Old\intranet\news\news.php on line 70Warning: exec() [function.exec]: Unable to fork [E:\InetPub\wwwroot\Intranet_Old\intranet\close_millweek_docs.vbs] in E:\Inetpub\wwwroot\Intranet_Old\intranet\news\news.php on line 71All MillWeek docs have been closed.----

<?php							  $tmp = "";$msg = "";							  if(!empty($_REQUEST["file_m"])){<	if($_REQUEST["file_m"] = "m")/*line 70*/	{/*line 71*/		$tmp = shell_exec('net file | Find /i "Millweek.pdf"');/*line 72*/		exec('E:\InetPub\wwwroot\Intranet_Old\intranet\close_millweek_docs.vbs');		$msg = "All MillWeek docs have been closed.";	}}echo $msg;	echo '<font color="black"><br><br> ' . $tmp . '<br></font>';?>

Below is the Visual Basic script for the file referenced in Line 72:

Dim ServerNameDim FileNameServerName = "CBVA006FILE1" 'example. fileserver.microsoft.local or fileserverFileName = "E:\GROUP\BIWeb\MillWeek\Millweek.pdf"Set objConnection = GetObject("WinNT://" & ServerName & "/LanmanServer")Set Shell = CreateObject("WScript.Shell")Set colResources = objConnection.ResourcesOn Error Resume NextFor Each objResource in colResources    If objResource.Path = FileName Then	Shell.Run "net file "& objResource.Name & " /close",1,True    End IFNext

I've checked and verified that the user account does have read/write/execute permissions on the web server and where the documents reside on the shared server. Also, I was able to successfully run the 'net file' command from the Command Prompt which did display the file that I had opened on my computer...c:\>net file | find /i "Millweek.pdf" response back: 2815781310 E:\cbv06file1\...\Millweek.pdf.Anyone that can provide some suggestions or answers on how to resolve this error is welcomed to reply back.Thanks!

Link to comment
Share on other sites

Looks like the classical Windows quotes problem to me.Try to add quotes around all program arguments, like:

'net "file | Find /i "Millweek.pdf""'

Edited by boen_robot
Link to comment
Share on other sites

Got the error "Unable to execute..." when trying to run an external program with shell_exec under Windows XP, IIS 5, php 4.3.7 Solved by giving the IIS user (IUSR_...) execution privileges on the system file %systemroot%\system32\cmd.exe This should be used carefully because may represent a server's security hole.
Link to comment
Share on other sites

Are you actually using IIS or Apache as your web server? Is PHP running as (F)CGI or as an Apache module?Either way, try it like:

'"net file | Find /i "Millweek.pdf""'

(the whole command in quotes this time...)

Link to comment
Share on other sites

You should be able to right-click on cmd.exe, Properties, Security, find Internet Guest Account, and check that one. If it's not listed in the box, you'll need to add it.Also, yeah, this should only apply to IIS, unless you set up Apache to use that account also. By default Apache uses the System account, which should already have access to cmd.exe.

Link to comment
Share on other sites

You should be able to right-click on cmd.exe, Properties, Security, find Internet Guest Account, and check that one. If it's not listed in the box, you'll need to add it.Also, yeah, this should only apply to IIS, unless you set up Apache to use that account also. By default Apache uses the System account, which should already have access to cmd.exe.
Thanks for your help as I was able to find out that our servers were recently upgraded and the account was not set up with execute privileges. I had looked at the old file server by mistake for the information.I'm in the process of having our IT Admin set it up so that this won't be an issue any longer. I appreciate your help....Thanks!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...