ready2drum Posted September 2, 2009 Share Posted September 2, 2009 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 More sharing options...
boen_robot Posted September 2, 2009 Share Posted September 2, 2009 Looks like the classical Windows quotes problem to me.Try to add quotes around all program arguments, like: 'net "file | Find /i "Millweek.pdf""' Link to comment Share on other sites More sharing options...
ready2drum Posted September 2, 2009 Author Share Posted September 2, 2009 Looks like the classical Windows quotes problem to me.Try to add quotes around all program arguments, like:'net "file | Find /i "Millweek.pdf""' okay..I'll give that a try and reply back with the results...Thanks! Link to comment Share on other sites More sharing options...
justsomeguy Posted September 2, 2009 Share Posted September 2, 2009 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 More sharing options...
ready2drum Posted September 2, 2009 Author Share Posted September 2, 2009 I appreciate your help on this too...I'll double check to see if the execution privileges have been setup. Thanks! Link to comment Share on other sites More sharing options...
ready2drum Posted September 2, 2009 Author Share Posted September 2, 2009 okay..I'll give that a try and reply back with the results...Thanks!Adding the double quotes generated the same error, except this time it referenced lines 71 and 72....and also, I did verify that the execute privileges are setup for the cmd.exe. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 2, 2009 Share Posted September 2, 2009 The IUSR account has execute privileges on cmd.exe? It's not like that by default. Link to comment Share on other sites More sharing options...
boen_robot Posted September 2, 2009 Share Posted September 2, 2009 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 More sharing options...
ready2drum Posted September 2, 2009 Author Share Posted September 2, 2009 The IUSR account has execute privileges on cmd.exe? It's not like that by default.I thought that's what I read....maybe I'm looking in the wrong place. I'll do another check and reply back. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 2, 2009 Share Posted September 2, 2009 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 More sharing options...
ready2drum Posted September 2, 2009 Author Share Posted September 2, 2009 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 More sharing options...
ready2drum Posted September 2, 2009 Author Share Posted September 2, 2009 Update.....the program works fine thanks to your suggestion...have a great day! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.