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.
Related
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.
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.
First Note: Sorry this is long. Wanted to be thorough.
I really hate to ask a question when there's so much out there online but its been a week of searching and I have nothing to show for it. I'd really appreciate some help. I am a noob but I learn very fast and am more than willing to try alternate languages or whatever else it might take.
The goal:
What I'm trying to do is build a Netflix remote (personal use only) that controls Netflix on the server (Windows 7 PC 32-bit) via keyboard shortcuts (example: spacebar to pause) after a button is pressed in a php page on my ipod touch or android phone. Currently the remote uses USBUIRT to control the TV and IR devices without issue. If you have any alternate methods (that I can build, not buy) to suggest or other languages I could learn that can achieve this, I'm happy to learn.
The issue:
PHP's exec() and system() commands will not launch the python script (nor an exe compiled with py2exe) that simply presses the Windows key (intended to press the key on the server, not the machine loading the php page). I can use USBUIRT's UUTX.exe passing arguments with exec() to control IR devices without issue. But my exe, py, nor pyw files work. I've even tried calling a batch file that then launches the python script and that batch will not launch. The page refreshes and no errors are displayed.
Attempted:
Here's a code that works
$exec = exec("c:\\USBUIRT\\UUTX.exe -r3 -fC:\\USBUIRT\\Pronto.txt LED_Off", $results);
Here's a few attempts that don't work
$exec = exec("c:\\USBUIRT\\test.py", $results);
$exec = exec("python c:\\USBUIRT\\test.py", $results);
$exec = exec("C:\\python25\\python.exe c:\\USBUIRT\\test.py", $results);
All of those I've tried without the dual backslashes and with forward slashes and dual forward slashes. I've left off passing it to variable $exec and that makes no difference. $result outputs
Arraystring(9) "
Copying everything in the exec() into command line works correctly. I've tried moving the file to the htdocs folder, changed folder permissions, and made sure I'm not in safemode in php. Var_dump returns: Array" Using a foreach loop gives no info from the array.
My logs for Apache show only
[Sat Sep 10 19:54:09 2011] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/announce
Setup: Apache 2.2, python 2.5, and php 5.3. Running this on Windows 7 and only connect on the local network, no vpn or the like. Given every associated folder (python, htdocs, the cmd.exe file, usbuirt folder) IUSR, admins, users, and everyone with full control just for initial testing (later I'll of course tighten security up). Safe mode is off on php as well.
Notes: This code I saw on another similar issue doesn't work:
exec("ping google.com -n 1");
No errors in error.log nor event viewer. Putting it inside ob_start(); and getting the results with ob_get_clean(); gives me absolutely nothing. No text or anything at all. I've tried a lot more but I've already written a novel on here so I'll just have to answer the rest as we go. I'll post the full php source or the python script if that is needed but all it does is import sendkeys and press the windows key to pop open the start menu as a basic visual test. I don't know if its permissions, the way I have my setup running, my coding... I just don't know anymore. And again I apologize this is so long and if you do answer, I really appreciate you taking the time to read all this to help out a total stranger.
The PHP server running the script is most likely running as a different user (Network Service) than the account logged in at the GUI Console. I think this kind of setup might work under XP, and/or with the "interactive" field enabled on the service. However, I believe in Vista/7 it is blocked on security grounds. Details are a bit fuzzy as I'm now in front of a Linux box.
A solution would be to run php manually in the session that is running netflix and try again. If this doesn't work, I once wrote a simple client/server in python that takes key commands and converts them to keystrokes. Was pretty easy to do.
Figured it out thanks to the excellent help from Winston Ewert and Gringo Suave.
I set Apache's service to the Local System Account and gave it access to interact with the desktop. This should help if you have Windows XP or Server 2003, but Vista and newer there's an Interactive Services Detection that pops up when you try to launch GUI applications from php. Every command was executing correctly, but were doing so in Session 0. This is because Apache was installed as a service. For most people I would think that reinstalling without setting up Apache as a service would work, but I was considering moving to XAMPP anyway, so having to uninstall Apache helped push my decision.
Ultimately all of the codes I wrote in my original post now work as a result, and my project can move forward. I hope someone else stumbles across this and gets as much help from Winston Ewert and Gringo Suave as I did! Thank you both very much!
I run an executable called Test.exe via exec which in turns runs Outlook.
I am able to run the Test.exe fine but I get the error:
Rejected Safe Mode action : Microsoft Office Outlook. in the windows event viewer.
If I run Test.exe myself via DOS it works fine and no errors. So its something to do with how PHP is running this exectuable. I've enabled apache to run as an admin account but the same thing happens.
What else should I be doing so that Apache can run the executable without any problems?
It works from the command line but not from the Apache process. Not surprisingly because Apache probably runs as a service, with a system account (Non-Desktop interactive).
If you reconfigure the service to run as a user with the right to logon locally and mark the service to be allowed 'Interaction with Desktop', I expect you could do this.
However, I'm at a total loss why anyone, at all, would want to start Outlook from a webserver application....
Sehe is right (but for some reason I cannot comment to his post, whatever...). Usually, you should access MS Office facilities via external code using specific OLE interfaces. You never use CreateProcess to start Outlook or Word from your program, it would be pointless because how can you control it after launching it?
I suggest you to check if you really need this, and if there's a more clean way to do it. You can try to create an external C#/VB.NET executable that performs all the automation you may need to do with Microsoft Outlook, indeed.
What is the actual scenario?
And, I don't like to correct people but if I don't, someone else will in the future and it'll be annoying. Don't say "via DOS" when you use a prompt under Windows. :D
i too am perplexed by would anyone would want to do this.
If you REALLY wanted to do this i guess you could run it as "start test.exe" or write a batch file that would run it. basically anything that would cause a different process to be the one actually launching the app.
I am getting daily data dump via e-mail, which is being processed by Access (based on the Outlook rule, VBA is extracting the attachment and running Access procedures, so I get a report).
As data dump is getting bigger and bigger, and having in mind that Access is run locally which consumes my resources, I want to set up a PHP/MySQL server to make it more efficient.
The first challenge I face is how to connect Outlook rule with PHP execution? (as I will have Outlook set up on the Windows based machine, with apache/mysql set up (WAMP))
Anyone can share some insights on how to start PHP execution from Outlook?
Thanks for the help!
Srdjan
If you have an existing setup using Access and VBA, and you just need a better database behind it, could you not just use MySQL without PHP and use the MySQL ODBC driver instead of the Access connection you are using at the moment (assuming you are currently using ODBC to connect to the access database)
This way you wouldn't even have to have mysql running locally if the hit is too high on your local machine and it should be pretty straightforward in that you shouldn't have to make to many changes to your vba code.
Of course, whether this will do it depends on what else is going on in your access db
If not you could try using php and using the PHP Command Line Interface (CLI) which you should be able to call as an external executable from Outlook. Just pass php.exe the name of the php script you want to run
UPDATE:
I am not a VBA expert by any means but it looks like the shell function would let you run the PHP CLI from within VBA
Shell("path/to/php.exe phpscript.php")
http://msdn.microsoft.com/en-us/library/xe736fyk(VS.71).aspx
Of course this will only work if you can get to php.exe on the wamp machine (ie is a local machine or you have network access to the appropriate folder)
Alternatively, if the Wamp server is to be a separate machine then you could trigger the php script to be run by calling a url. I think the XMLHTTP object will do this for you
Dim xmh As Object
Set xmh = CreateObject("MSXML2.XMLHTTP")
xmh.Open "GET", "http://urlofphpserver/script.php", False
xmh.Send