Hello

I would like to start an .exe file on client machine with one argument:

C:>"C:\Program Files\MyProgram\MyProgram.exe" "C:\www\MyFile.txt"

This will start a certain report with this .exe file. This code does not do anything:

exec("C:\Program Files\MyProgram\MyProgram.exe");

I have not added the argument, since the first step is to get the program started..

How can I debug this?

I should not have security issues here, because in Intranet. Safe mode off

Is there some library or .dll missing?

Client pc is Windows and so is server

Thanks!!!

    If by "client machine" you mean the machine running the php script, then exec will work assuming you do not have safe mode turned on in php.ini, or that specific directory is set as safe_mode_exec_dir or whatever the options is called (read the man page for exec).

    If by client machine you mean any other machine than the one running the php script, then you obviously can't do this. Imagine the havoc if every computer connected to the internet could be told to format c: or whatever.

      Hello, yes if running on locahost this does not work. It is Windows. Can yje space in program Files create a problem? I guess I have to have do some service replying on the other side (if not on local machine) to get the command working if not on local machine

        You can ONLY get it to work on the machine executing the script.

        If you want to execute something on a remote machine, THAT machine has to run the script which contains the call to exec(). The common way to execute a script on a remote machine is to install a web server on that machine, then enter its url containing path and filename info for the script you wish to execute.

        AmIStupidOrWhat;11013547 wrote:

        Can yje space in program Files create a problem?

        Anything can create problems. Yjes paceh is most likely one of them. Not properly yeshaping bagglash is another. Looking in the error log would tell you.

          How can I solve this problem with the space in Program Files? How do I get an error code? Thanks!

            google "php.ini" to find the man page for php ini directives. The 3 things of concern are: error_level, log_erros, display_errors.

            As for finding php.ini and a pretty list of current directives used, create a script which calls phpinfo().

              AmIStupidOrWhat wrote:

              How can I solve this problem with the space in Program Files?

              The same you did it in the command line of your original post - put it in quotes.

               exec("\"C:\\Program Files\\MyProgram\\MyProgram.exe\"");

                Thanks for reply..

                Putting it in quotes does not help:

                exec("\"C:\WINDOWS\system32\notepad.exe\"");

                This starts notepad from cmd prompt, but not from php script. php.ini safe mode is off.
                MyProgram.exe makes the script to run for ages so some problem with MyProgram.exe but how come notepad.exe does not work.

                  Because as the manual page for exec tells you, your script will wait until exec has finished, which is when the called program has finished executing. It also tells you how you can circumvent this by redirecting output.

                  It is indeed your script which launches notepad, not some randomly appearing shell which suddenly pops up and does it. Executing notepad.exe does however create a shell instance and is similar to what would happen if you ran cmd.exe and in the shell executed notepad.exe. If you don't wish for the shell to appear, you'd have to create a COM instance

                  $ws = new COM("Wscript.shell");
                  

                  This will let you execute notepad.exe without the shell showing. See this page for more info on options for run().

                    Hello

                    Do you mean now that it is not as simple as when writing in command prompt the following :

                    C:>C:WINDOWS\system32\notepad.exe C:WINDOWS\system32\test.txt

                    Notepad is launched and test.txt is opened with the text hello world. This is exactly what I want to do.

                    But it not as easy as :

                    exec("\"C:\WINDOWS\system32\notepad.exe C:\WINDOWS\system32\test.txt\""); in php?

                    And this only on localhost I want to do this on a remote pc. How come .pdf files opened then across the internet?

                    I am grateful if proffs like you would help to open this up for me

                      How about if I just open the file and Windows should then recognise the file as the file to be opened with MyProgram.exe. Or if not recognised then the pop-up window Open with...? Is this possible to do with PHP?

                        AmIStupidOrWhat;11013727 wrote:

                        But it not as easy as :

                        exec("\"C:\WINDOWS\system32\notepad.exe C:\WINDOWS\system32\test.txt\""); in php?

                        No, because that syntax is incorrect. You'll be exec()'ing the string:

                        "C:\WINDOWS\system32\notepad.exe C:\WINDOWS\system32\test.txt"

                        You either need to a) remove the quotes, or b) use the quotes properly (e.g. the program to be executed and the first parameter to pass to that program should each be in their own separate pair of quotes).

                        AmIStupidOrWhat;11013727 wrote:

                        And this only on localhost I want to do this on a remote pc.

                        Not possible, and the reason why should be obvious. Otherwise, you're suggesting that you should be able to execute really_nasty_trojan.exe on my PC remotely.

                        Note that it is technically possible to achieve this if: a) you have administrator credentials on the remote PC, and b) the remote PC is on the same LAN as where you're executing the command (or there's at least some tunnel/path from the two PCs that doesn't block the required communication protocols), and c) any other requirements specified by the 3rd party application/tool you use to do this. As an example for that last bit, the (previously) SysInternals tool PsExec can be used to do this assuming the requirements mentioned in this article (last paragraph under heading "The PsTools Suite") are met.

                        AmIStupidOrWhat;11013727 wrote:

                        How come .pdf files opened then across the internet?

                        Because they follow the same process as any HTML document, image, etc. The browser and/or PDF reader on your PC makes an HTTP request to your webserver for the PDF document, your webserver sends the raw binary data back as a response, and your browser and/or PDF reader renders that binary data as a PDF document.

                          Write a Reply...