0

I have installed Wampp Server. Now what I want is, if I open http://localhost.com/run.php it opens Notepad

I tried, all these three .. none of them executed notepad.

<?php exec("notepad.exe"); ?>
<?php shell_exec("notepad.exe"); ?>
<?php system("notepad.exe"); ?>

What is the solution? Please help!

4
Contributors
8
Replies
14
Views
6 Years
Discussion Span
Last Post by mschroeder
0

Do you have anything else running successfully in your Wampp server environment? Make sure something is working before trying this again. This is a general approach that works:

<?PHP

    exec("notepad", $output, $return);
    echo "The command returned $return, and output:\n";

    echo "<br><pre>";
    var_dump($output);
    echo "</pre>";
    
?>

You can use notepad or notepad.exe it will work either way. For notepad, there is no output so the last part isn't needed in that case. To see it work where there is output, use a command like ipconfig in place of notepad.

Edited by chrishea: n/a

0

I just tried this myself and confirmed what you're seeing. However, if you open up the task manager, go to the Processes tab, and then click at the bottom-left "Show processes from all users", you'll see your instance of notepad.exe running under the SYSTEM user (or which ever user the web server is configure to run under). If you terminate the process, your script will stop loading as well.

I'm not sure what the solution here would be, if there even is one. What you essentially want to do is launch a program on a client machine via a PHP script executing on the server. What's actually happening is the PHP script is launching notepad on the server side. Even though they're both (client and server) the same machine in your case, you have to think about them as two separate entities.

If I think of a solution, I'll let you know. The easiest method (however it's flawed) would be to have the web server service run using the same user account that you log in with. That will open up security issues and potentially a whole realm of other issues, but maybe you can at least try it and see if it works.

Edited by dcdruck: n/a

0

You would need to use runas on windows to run notepad.exe as the specified user:

<?php
exec('runas /user:ComputerName\UserName "notepad"');

However, if the user account requires a password it will prompt and can not be completed via the command line directly. You could create a vb script or something that fills the password automatically if this is a requirement. There are lots of examples of automating the runas logins using vb and such via google.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true
http://www.tek-tips.com/faqs.cfm?fid=2760

0

@DCDRUK

No, I want to run the application on the server from PHP, not on client side. I cannot actually tell what I am doing, but I can tell you an example of what I am doing.

* A user comes on my website (PHP Site), fill in some value in text boxe and hit Submit. (This page is hosted on a web hosting, not my windows server, i.e. my PC)

* The action brings the request to my Windows PC (i.e. my PC which has a public IP and is acting as a windows server with Apache on it).
(Note: My Windows PC referrs to as my local system which has web server installed on it, and Web Hosting referrs to as lets say a Hosting account bought from GoDaddy)

* On my Windows PC, I have an application which is let say placed in C:\Program Files\ABC\myapp.exe

* This application accept some parameters like myapp.exe -Display "Hello World"

* This "hello world" was basically passed from my PHP website when user entered the value in text box.

* The application just exectues (whatever it has to do). Thats it. I just need to send the user entered value to my Windows PC's application.

0

I thought it was odd you were trying to open notepad with php...next time you need to describe your problem exactly like your last post.

You have a few ways to achieve what you're trying to do. You can either make the form post directly to your local windows environment with the form values, process the request, and then redirect the user back to your webhosting environment.

-OR-

You can have the form post to your webhosting environment, process the request and as part of the processing have that machine make a POST request to your home server using cURL or Sockets. Your home machine won't know the difference between the requests, except the user will be unaware of the additional request happening.

The other variation on this, would be if the the communication does not need to be in real time. In which case you could handle the transaction on your hosting machine, and have a cron task that runs at an interval, determines your home machine is available, attempts to send n number of pending requests to it and then updates your hosting machine with some form of result.

This allows the process to happen in the background and not slow down the user's experience on your site.

http://php.net/manual/en/book.curl.php
http://php.net/manual/en/book.sockets.php

0

@mschroeder

Thank you for your reply. You told me what to do, but didn't tell me how to do. I already know this that I can use these procedures, but how to code them is what I dont know :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.