Exec or Permission issue on IIS 8 - php

I have a problem with my php webseite.
It is suppossed to run a batch file. The Batch starts a programm.
That programm is reading a file and creates a bmp and txt file.
This is my php code:
exec('cmd.exe /c "path\\to\\file.bat"');
The problem is when i run the php script i can see the programm in the task manager as "background processes" but no bmp or txt file is created. also the programm shuts itself down after creating the files.
i tried giving permission to the users but it seems i still make a mistake somewhere.

I had the same problem 3 months ago. The file is not created because the instance of cmd you’re running does not have administrative permission (i.e. run as administrator). The only solution I could find was to give the application pool for that app administrative permissions on cmd which ultimately resulted in me implementing a completely different approach since giving a website admin rights to the server is bound to end badly.
Hope this helps.

Related

Change php upload tmp file permission. Clamav deamon cant access

I'm currently developing a new website where a lot of files will be uploaded and downloaded.
When a file is uploaded to the server clamav will start a virus scan on the tmp file before it will be moved to the http server. Everything works great except when i use clamscan and it seems like clamav needs to upload the hole virus database before the scan starts every time and this stress my cpu to 50% for maybe 10 - 20 seconds.
This seem to be a big problem because if two users upload files at the same time to my website it will probably be very slow.
So I installed clamav deamon because it runs in the background and already have the virus database loaded so a lot of time and cpu power can be saved. But to the problem...
When i use clamdscan (clamav deamon) it cant access any of the tmp files that's uploaded with the php script. It only works when i use clamscan. This is probably because clamdscan is running in the background and uses some very strict user permissions.
But how can i solve this? Can i change the tmp php upload file permission from 0600 to 0644? Is that safe? Or should i change permission for clamav deamon?
I don't really know how to do this and if someone know and what to shear I'm very thankful.
Try passing --fdpass as an option to clamdscan.
I had the exact same issue and it worked for me.
--fdpass
Pass the file descriptor permissions to clamd. This is useful if clamd is running as a different user as it is faster than streaming the file to clamd. Only available if connected to clamd via local(unix) socket.
Source: https://linux.die.net/man/1/clamdscan

running exe app using php exec funtion make the page hangs

I am using apache server under xampp. I have some matlab exe file that I want to execute. I used this template
$tmp = exec($command, $output, $return_var);
while $command contains the exact command to execute the file using cmd.
What is happening is the page hangs and when I debug, I found that the server hang while calling this exec command.
I searched the web and tried many things like run the Apache service and my user account and give the user all administrator privileges, but unfortunately it still stuck.
Any help or advice would be appreciated.
The problem with my code was because the Matlab code is accessing file system and also reads an excel sheet. So, it was all about permissions.
The solution for this problem has 2 parts:
1. Apache should run as a a windows service with checking allow service to interact with desktop in the properties.
2. I found that there is no way to access windows COM objects to read excel in normal way. So, instead we should use xlsread in basic mode.
That's all.

Using PDFCreator's Command Line Arguments in PHP exec()

I have tried to use the Zend Framework to do my PDF conversion in PHP but cannot figure out how to install it. I found this program that allows for PDFs to be printed/converted via the command line, so I thought I could do an exec() command in PHP to run the program and convert my file on the server for me.
The program is PDFCreator from pdfforge.org and I am trying to convert .DOC files to .PDF files. This command line below works perfectly when running from cmd.exe. However, when running it from PHP I believe that it is trying to execute under the user System and not working properly. (I did a php exec('whoami') and it came back as System.) I also changed the user of which Apache opens up as to an Admin account and still have been unable to get it to work.
"C:\Program Files\PDFCreator\PDFCreator.exe" /OptionsFile"C:\PDFCreator.ini" /PF"C:\test.doc"
Any thoughts as to why it I cannot get the same behavior when running the command using exec()?
Thats because Apache user and account user should be the same, ex: your windows user is Pedro, so Apache user should be Pedro...you shoul open the services.msc and in the session tab allow apache to interact with the current desktop....in that way, the share the same windows session and desktop....but it shoud represent a security risk and it's not recommended.
Saludos.

PHP - exec,shell_exec,system not working

i read so many similar questions but nothing works with me
im using wamp 2.2 ,Apache 2.0 , PHP V5.3.8
safe_mode=off - disabled_functions deleted from php.ini i'm trying to exec
exec("chrome.exe google.com");
nothing happens and when i try
exec("calc");
the windows shows weird message to execute calc in different user although i changed the user for the apache service to Administrator and i verify the user using
exec("whoami");
where is the problem?
Environment path for CMD and php shell might not be the same.
You either have to give entire path of the file, or export the path of chrome.exe in php first
Also, I believe that chrome.exe opening a page requires XServer, php can't open graphical interfaces in shell. These commands are not passed to actual shell as a parent, so php file can't "launch" applications for you.
Please read specifics of the exec function:
PHP exec Reference
Also try adding 2> errors.txt to see what are the errors if any in the execution of the programme.
--
The program needs to know what X server to connect to, and it needs to have permissions to connect to that server. You specify the X server with the DISPLAY environment variable; this will usually be set automatically if you are running the PHP program from a terminal in
X, or from a GNOME panel or something similar; however, if you are running the PHP script in some other manner, it likely won't know what X server to connect to.
X has various ways of specifying permission to connect to a server, but the most common one is using a file called ".Xauthority" in the users home directory. Because only the user who is logged in at the X server can read this file, they are the only user who can run GUI programs. So, if you start the PHP user as the same user who is logged in at the X server, you shouldn't have any problem with permissions. However, if the PHP program is running as a different user, you will have to give that user permission to access the X server.
Reference: http://bytes.com/topic/php/answers/838364-cant-launch-graphical-apps-php-exec-ubuntu-8-04-system
(I know that link is for linux and won't have exact same solution for Windows, but exec() still needs to know which X interface to refer to)
Stop Apache running as a service.
When windows runs a service it it is not running directly as the user that started the server or manages due to this it could well be starting chrome in a service environment so you wont see it load on your desktop there are 2 ways to get around this
Stop apache service browse to your apache directory and run httpd.exe manualy then try your script it should work or if it is not required to be running though a web request so it not using anything from the browser you can allow it to work with c:\wamp\php\php.exe yourfile.php (your php path should be replaced for c:\wamp\php)
Try PHP script?
<?php shell_exec('notepad.exe');?>
It's working.

PHP: COM object not created in schedule task (instead hangs)

I have a PHP script that runs a process to generate letters on a Windows server. The file is current set up as a Scheduled Task.
In the script, the COM object is instantiated to work with the appropriate files. When it is run as a Scheduled Task, the line to instantiate the COM object does nothing and hangs the script (rather than returning any result). The script will never terminate.
$this->word = new COM("word.application");
I believe that there is no issue with the script itself, as I can run the batch file directly (with no issue). This problem only seems to come up when we try to automate it.
I think there is some permissions issue going on, but I'm not entirely sure.
Thanks for any help!
Edit:
More information about the system:
Windows 2008 Server Standard without HyperV
Microsoft Office Word 2007
PHP 5.3.10
Attempting to Automate
I have found the solution. It was a profile issue.
In:
C:\Windows\SysWOW64\config\systemprofile
check to see if the Desktop folder exists.
If it doesn't, create it.
It has this issue because it is expecting the folder, but hangs when it can't find it.

Categories