473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Control Windows from PHP (esp. run .bat files)

103 100+
I have tried posting in PHP forum but no reply. I think it's not a problem with PHP anyway so perhaps someone in this forum can help.

When I use the code below to try and launch notepad.exe from within a PHP script using the exec() function, I can see the process has been added to the process list (from task manager) but notepad hasn't started! The process cannot be forced to quit either.

The exec() function seems to work but I want the application to launch properly - is there a trick when using the command prompt to having a programme actually launch, as compared to just having the process start?


Expand|Select|Wrap|Line Numbers
  1. $cmd='notepad.exe'
  2. exec($cmd);
  3.  
My system is: win2k pro, apache 2, php 5.2

Thanks!
Jul 20 '07 #1
6 11584
dafodil
392 256MB
I have tried posting in PHP forum but no reply. I think it's not a problem with PHP anyway so perhaps someone in this forum can help.

When I use the code below to try and launch notepad.exe from within a PHP script using the exec() function, I can see the process has been added to the process list (from task manager) but notepad hasn't started! The process cannot be forced to quit either.

The exec() function seems to work but I want the application to launch properly - is there a trick when using the command prompt to having a programme actually launch, as compared to just having the process start?


Expand|Select|Wrap|Line Numbers
  1. $cmd='notepad.exe'
  2. exec($cmd);
  3.  
My system is: win2k pro, apache 2, php 5.2

Thanks!
Try to download this program, it helps:
http://www.microsoft.com/technet/sys...es/psexec.mspx

After installing it....

try to use this format:
Expand|Select|Wrap|Line Numbers
  1. exec("psexec -d blah.bat");
  2.  
-------------------------------------------------------------------------------------------------------------

If you don't like the above solution

You can also use the run.......

Expand|Select|Wrap|Line Numbers
  1.  
  2. //start Notepad.exe minimized in the background:
  3. $WshShell = new COM("WScript.Shell");
  4. $oExec = $WshShell->Run("notepad.exe", 7, false);
  5.  
  6. //start a shell command invisible in the background:
  7. $WshShell = new COM("WScript.Shell");
  8. $oExec = $WshShell->Run("cmd /C dir /S %windir%", 0, false);
  9.  
  10. /*start MSPaint maximized and wait for you to close it before continuing the 
  11. script:*/
  12. $WshShell = new COM("WScript.Shell");
  13. $oExec = $WshShell->Run("mspaint.exe", 3, true);
  14.  
  15.  
Hope this helps....
Jul 20 '07 #2
henryrhenryr
103 100+
Hi dafodil

Thanks very much for your reply - I think I'm very close.

Tried both methods. They both seem to work, except that the application is never maximised.

On the second method, for the first one (...->Run(notepad.exe, 7, false); ), the process launches (according to task manager) and I can close it with task manager.

For the third one (...->Run(mspaint, 3, true); ), the script continues running and the application starts in the background but doesn't maximise. The script only stops running when I close the process in the task manager.

Perhaps it's something preventing Apache telling windows to maximise it? I've had a look on some sites for some clues but I can't seem to work it out...
Jul 21 '07 #3
dafodil
392 256MB
Hi dafodil

Thanks very much for your reply - I think I'm very close.

Tried both methods. They both seem to work, except that the application is never maximised.

On the second method, for the first one (...->Run(notepad.exe, 7, false); ), the process launches (according to task manager) and I can close it with task manager.

For the third one (...->Run(mspaint, 3, true); ), the script continues running and the application starts in the background but doesn't maximise. The script only stops running when I close the process in the task manager.

Perhaps it's something preventing Apache telling windows to maximise it? I've had a look on some sites for some clues but I can't seem to work it out...
Try this to give Apache permission to interact with your desktop:

Start>Run>services.msc
Right click "Apache...", select properties.
Click on the "LOG ON" tab
Check the box "Allow this service to interact with desktop"
Click OK
Restart Apache
Jul 23 '07 #4
henryrhenryr
103 100+
Hi Dafodil

I don't seem to be having much luck here. Followed those steps but no effect.

The exec() function definitely works because I can run commands directly through it. Simple example would be ipconfig which works and returns expected output with the following:

Expand|Select|Wrap|Line Numbers
  1. exec("ipconfig /all",$output);
  2. var_dump($output);
  3.  
I don't know why it refuses to maximise or start applications. Also seems to have trouble executing batch files - exactly the same command in a batch file doesn't work.

I suppose I'll stick to using simple commands with the exec() function for now. Any further ideas would be really welcome but thanks for your help up to now!
Jul 25 '07 #5
henryrhenryr
103 100+
Hi Dafodil

The problem seems to be fixed. Think the last part helped although only after I restarted my whole system for some reason.

And I realised that some of my commands in exec() weren't properly escaped so they weren't being recognised.

Thanks for your help!

Henry
Jul 26 '07 #6
dafodil
392 256MB
Hi Dafodil

The problem seems to be fixed. Think the last part helped although only after I restarted my whole system for some reason.

And I realised that some of my commands in exec() weren't properly escaped so they weren't being recognised.

Thanks for your help!

Henry
Welcome. Post again whenever you face any problem.
Jul 26 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Brett Gerhardi | last post by:
Hi all, I'm having a nightmare with Windows Installer projects and souce control. My situation is that I have a few related windows application / dlls, some generic shared library files and a...
5
by: Shi Jin | last post by:
Hi there, I am now having a puzzle regarding what a function call actually does when called. I have a simple code to see what's going on. It is simply calling another simple function from...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
0
by: Chris Schremser | last post by:
I have a question regarding embedded controls in IE. We are looking to replace a small VB ActiveX control with something written in C#. We have written the control and it instantiates correctly...
0
by: Mobile Boy 36 | last post by:
I'm trying to make a very simple Textbox with a FocusColor property...When the focus changes to the control, the backcolor must change automaticly to the color set by the focusColor property....
2
by: Matt Theule | last post by:
I need to be able to allow users to drag files to a list box on a web page. To this end, I created a Windows Control and hosted it in a WebForm. When the file is dropped onto the listbox, the...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
9
by: Charts | last post by:
I use VS2005 to build a asp.net 2.0 project. I want to be able to click a button on the page and have a dialog window appear where I can navigate the folders to get hold of a file path to load...
2
by: Jens Kallup | last post by:
Hello Newsgroup, I had program a little tool, thats output some assembler output: --- .section .rdata, "dr" LC1: .ascii "eins: %g\0" ..text ..globl _dbase_main
0
by: ChopStickr | last post by:
I have a custom control that is embedded (using the object tag) in an html document. The control takes a path to a local client ini file. Reads the file. Executes the program specified in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.