www.webdeveloper.com
Results 1 to 3 of 3

Thread: I wish to execute .exe file from my php program. I am using Window 7, WAMP.

  1. #1
    Join Date
    Feb 2014
    Posts
    1

    I wish to execute .exe file from my php program. I am using Window 7, WAMP.

    I wish to execute .exe file from my php program. I am using Windows 7 , WAMP on my local machine. My code is -

    exec('C:/wamp/www SkypeSetup.exe');

    /*AND*/



    $answer = shell_exec("C:/wamp/www/SkypeSetup.exe -args");
    echo $answer;
    But above code is not working. Please help. Thanks in advance.

  2. #2
    Join Date
    Feb 2014
    Location
    Canada
    Posts
    155
    Ideally, you would want it so that the command you're passing will be executed without any command window popping up and will the rest of your page will not be forced to wait until the exec is finished. Also, if you're taking in user input, your code will allow for the user to execute any command, including file deletions. Read through the documentation HERE and take a look at some of the user comments.

  3. #3
    Join Date
    Feb 2014
    Location
    Ahmadabad, Gujarat, India
    Posts
    81
    Hello Friend, i heard this same questions in other thread, i am sharing the same information because the question you asked is similar as the earlier question..

    I have WAMP setup and I need to execute a program.
    WinXPPro sp3
    Apache 2.2
    PHP 5.3

    Right now I'm failing on all my attempts.

    I have tried...
    shell_exec
    exec
    system
    passthru
    popen

    also opening a batch file and Python script that executes the program and I have no luck for now.

    I have been digging for couple of days and I can't find a solution for this problem.

    php file:
    PHP Code:
    $test = `F:\batch.bat`;
    $test = shell_exec('F:\batch.bat');
    $test = system('F:\batch.bat');
    $test = exec('F:\batch.bat',$output,$return);
    $test = popen('F:\batch.bat','r');


    batch file:
    PHP Code:
    $ECHO OFF
    "F:\Mozilla Firefox\firefox.exe"
    EXIT


    Start, cmd /c, cmd /d, don't work the way I want. Actually day don't execute the program. They just open a second cmd outside or inside the parent cmd.

    When I execute internal program... let us say "notepad" I can see in my task manager and Process Explorer that it is opening the "notepad" but it looks like a child process for Apache and it's not showing up on the screen.

    Suggesting Check:

    Is Apache running as a service? My guess is yes, and what is happening is Apache is launching under a different session/user than the one you are logged in as. Thus the window isn't visible to you. Unfortunately I'm not sure exactly how to fix that besides not running Apache as a service.

    Final Reply

    After you point me to the problem I went for investigation. So actually the problem is that any program that had to be run from php/apache it executes in different session and even if the user is the same I think it can't find the same session.

    The other difference that I notice is any program executed by cmd or explorer.exe are executed also as NT AUTHORITY\INTERACTIVE and any program from PHP/Apache is executed as NT AUTHORITY\SYSTEM.

    So some may ask so what... well it is not INTERACTIVE so I went to look for a way to start program in INTERACTIVE Authority and there was a Micro$oft Solution for that and it is called PsTools and their psexec.exe tool.

    The right command is:
    PHP Code:
    path/to/psexec.exe -i -s path/to/your/file.exe


    For now I think it is working. I will give it a better test to see if I can actually use it.

    Hope this can help you, if this will be helpful to you, please share your experience here. Best of Luck

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles