Web Hosting Talk







View Full Version : launch Windows program from PHP


SexualChocolate
02-16-2007, 03:39 AM
Hello all, Im trying to launch a program in windows from PHP. The only problem is, the program I want to launch has a GUI window that I would like to show up (the "server" is just my desktop running Apache 2.2/PHP 5.2 on Windows XP). Ive tried exec and shell_exec but it appears that you cant use them to run a program that opens a window.

for example, heres what Im trying to run :


"C:\Program Files\Windows Media Player\wmplayer.exe" "Z:\media\file.avi" /fullscreen

Is there any way to get this to launch windows media player like I want it to?

I have 0 Windows admin experience so I'm not sure where to begin.

Thanks,
Jason


Just a little background on the script Im writing, in case you were wondering why I wanted to do this :

Im writing a "remote control" web panel to be accessed by my PDA to control the desktop's volume and make playlists that would (as Im trying to) open Windows Media Player with the movies :)

edit: I've also now tried creating a batch file with the command and executing it from PHP, but it still doesnt seem to work :(

tiamak
02-16-2007, 08:33 AM
if you want to use your pda as some kind of remote controller for your desktop then it should work :)
at least it works fine on linux :D (just tested :D)
im guessing that maybe your command is not correct (u need to use \\ instead of \ ?)
did u get any error message? or just nothing happened?

SexualChocolate
02-16-2007, 02:41 PM
Thanks for the response-

If I shell_exec and capture the command line output, I get something when I run the batch file, but not when I shell it directory from PHP. When I double click the batch file it opens windows media player like it should, so I dont think its a problem with the syntax. :(

The output reads as below:


C:\Program Files\Apache Software Foundation\Apache2.2\htdocs>"C:\Program Files\Windows Media Player\wmplayer.exe" "Z:\media\filename.avi" /fullscreen
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs>EXIT


Which is the output if I were to go into the command prompt and type the command manually. The only difference is, when I do it manually, it opens wmp like it should, through php it doesnt launch the window.

SexualChocolate
02-16-2007, 02:59 PM
Update:

I was playing aruond with exec('notepad'); while watching the taskmanager, and it looks like it is running notepad, but under the username SYSTEM, not as Jason (me). So I'm thinking that if I can make it exec as Jason then it will show on my desktop. I just dont know how to do this.

dgeorge
02-16-2007, 04:28 PM
I know wscript (basically vbscript) will do what you want and you could call it from php.

Example wscript file pulled from net - Not Tested
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "Excel"
WScript.Sleep 500
WshShell.AppActivate "Microsoft Excel"
WshShell.SendKeys "%+(t)"
WScript.Sleep 250
WshShell.SendKeys "m"
WScript.Sleep 250
WshShell.SendKeys "~"
WScript.Sleep 250
WshShell.SendKeys "~"

If you really want to do it strictly in PHP, probably the only way you are going to be able to control the application once it is open is to use the COM functionality.
http://www.php.net/manual/en/ref.com.php
(see comments section for examples)

Windows media player object model
http://msdn2.microsoft.com/en-us/library/bb249259.aspx

Engelmacher
02-16-2007, 05:10 PM
Is your dorm room really so big that you need a remote control for your computer

Navid1
02-16-2007, 05:53 PM
Hey,

You have Palm ?? http://www.palminfocenter.com/view_Story.asp?ID=1586

paid one but worths the money?? http://www.junefabrics.com/pdareach/index.php

-Navid

SexualChocolate
02-16-2007, 06:46 PM
Is your dorm room really so big that you need a remote control for your computer

I was wondering if someone would bring that up :). I have a tuner card, and I like to watch recorded TV shows as I go to bed, so its nice to enque another show without having to get up ;)


Thanks for the links, Navid1. Unfortunately I am on Windows Mobile 5. There is a terminal services client, but it logs the current user out and logins in again to start a new session, thus closing all opened programs.

SexualChocolate
02-17-2007, 01:29 PM
So I've looked around at the options, and I think that wscript / vbscript wont work, as they are client side, right? So it would be trying to do the windows media player stuff on my pocket pc.

I've been playing around with the COM in php but am having a little trouble. If I use word.application like in the examples, MS word launches. But, the only Windows Media object I can create is WMPlayer.OCX (which doesnt launch media player).

Host81
02-21-2007, 05:54 PM
I've never done this myself (I'm a Linux host guy...)

There is a way of doing it in PHP... I know of a program called "CastControl" that uses it... you may be able to have a look at the source for that and see how they do it!

Dave - Just199
02-21-2007, 06:00 PM
VNC anyone?

crazylane
02-25-2007, 12:10 PM
I think....