Recent

Author Topic: Run windows exe on remote pc  (Read 18805 times)

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Run windows exe on remote pc
« Reply #15 on: April 04, 2016, 08:48:08 pm »
Thanks very much to all, guys.
It must be me.
The purpose of the mobile call to the PC is to get a JIT sales report.
Now, I have tried many things in WAMP and directly IN chrome.
For example, with aN html file that would simply call an EXE that  write a single line to a txt file.
Well, it does not do that: it downloads the EXE. I have tried with a PHP: same result.
So the question is "how do I EXECUTE the EXE in ok a web app, NOT DOWNLOAD?"
 

rvk

  • Hero Member
  • *****
  • Posts: 6989
Re: Run windows exe on remote pc
« Reply #16 on: April 04, 2016, 09:12:43 pm »
I have tried with a PHP: same result.
Did you try it with the Exec command in PHP??
http://php.net/manual/en/function.exec.php

Create a runmyexe.php with:
Code: PHP  [Select][+][-]
  1. <?php
  2.   exec('c:\\MYDIR\\MYEXE.EXE');
  3. ?>
And call it http://correct_ip_address/runmyexe.php. This should have worked.

You can read the text-file too, in PHP, and make it output to the browser so the test-file is downloaded. Or you can display it directly on that page.

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Run windows exe on remote pc
« Reply #17 on: April 04, 2016, 09:57:21 pm »
Thanks rvk, long time!
I tried in wamp and it does nothing.
I tried with Chrome, and it TYPES the php
content.
I gues by " http://correct_ip_address/runmyexe.php"
you mean put "runmyexe.php" in the localhost address?
I did this: i created this files
 Directorio de C:\wamp\www\temp

04/04/2016  02:57 p.m.    <DIR>          .
04/04/2016  02:57 p.m.    <DIR>          ..
04/04/2016  02:43 p.m.            41,984 my.exe
04/04/2016  02:46 p.m.                49 runmyexe.php
my.exe is a console program tha simply writes "Hello" on the screem.
runmyexe.php is
<?php
  exec('c:\\wamp\www\temp\my.exe');
?>
wamp\www is the local host for wampserver.

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Run windows exe on remote pc
« Reply #18 on: April 04, 2016, 09:58:18 pm »
php 5.4.16 is the version of the php form wampserer

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Run windows exe on remote pc
« Reply #19 on: April 04, 2016, 10:08:01 pm »
I've digged up an old thread here, perhaps it can be of use to you.

At least lots of interesting suggestions in that thread, even though version numbers are perhaps a bit out-dated.


Edit:
BTW: is it me or was it mentioned very late in this thread that we were talking about wamp ? Shame, as something based on this is a very neat approach
« Last Edit: April 04, 2016, 10:14:51 pm by molly »

rvk

  • Hero Member
  • *****
  • Posts: 6989
Re: Run windows exe on remote pc
« Reply #20 on: April 04, 2016, 10:16:54 pm »
First of all... if going to http://localhost/temp/runmyexe.php only outputs the content of runmyexe.php then I think you have PHP turned off or the .php extension is not set correctly.

Click the wamp icon and goto Apache > Apache modules and see if php5_module is checked.

Next, check under Apache > httpd.conf if there is a line like this:
AddType application/x-httpd-php .php

If all is correct you shouldn't see the PHP-raw output in a browser if you access it via localhost.

B.T.W. running my.exe doesn't automatically output Hello to the browser. You said your exe created a file. In PHP you can read that file and output it to the browser. If you want to output the result of my.exe screenoutput directly to the browser you need to use a parameter for Exec('command', $result) and your output will be in $result. See the manual-page I gave.
« Last Edit: April 04, 2016, 10:20:43 pm by rvk »

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Run windows exe on remote pc
« Reply #21 on: April 04, 2016, 10:44:10 pm »
Thanks molly.

RVK again my saviour, Thanks.
(stupid of me, i do want a different output than writing to the screen, but i wanted to make sure that the exe was NOT downloaded but executed).
In wampserver works fine.
in Chrome, I did put the same files in
C:\Inetpub\wwwroot\temp
my.exe should create a test.txt file with "Hello".
With Chrome does nothing, while with wampserver does creaate the file in its iown localhost (wamp\www\emp).
Any reason why?

rvk

  • Hero Member
  • *****
  • Posts: 6989
Re: Run windows exe on remote pc
« Reply #22 on: April 04, 2016, 10:52:35 pm »
in Chrome, I did put the same files in
C:\Inetpub\wwwroot\temp
my.exe should create a test.txt file with "Hello".
With Chrome does nothing, while with wampserver does creaate the file in its iown localhost (wamp\www\emp).
What is Inetpub?
You say in Chrome... Chrome isn't a webserver. So what exactly are your trying to do?

If you say it works with wamp, then what's wrong with using that?

Also... it's normal if you use Chrome to browse to http://localhost/temp/runmyexe.php you don't see anything because you only execute that my.exe. If you want some output you need to put more in there.
Code: PHP  [Select][+][-]
  1. <?php
  2.   exec('c:\\MYDIR\\MYEXE.EXE');
  3.   echo "Hello world";
  4. ?>

You could also put the commands in there to output the test.txt. But you need to make sure first that your PHP is running correctly.

Furthermore... (before you go any further)... from where do you want to call this page? Only from the same computer or from your local network? Or even from the internet? If you want to call this page from the internet (i.e. other location) then you also need to forward the correct port in your router. Do you have permission (or knowledge) to do that?

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Run windows exe on remote pc
« Reply #23 on: April 04, 2016, 11:54:51 pm »
From epergola's first post:
Quote
From the mobile, using its browser
Start your chromium browser, assuming that to be the browser on your mobile device

Quote
I want to send a request (by opening an html file on the PC) to the remote PC
You have WAMP, which is your server. You need to connect your browser to that WAMP server.

(see also rvk's answer: local ? using a router ? over the internet ?)

For instance on my local network (using a router) i 'connect' the local browser on my machine (ip address 192.168.0.1) to my webserver by typing the url in the address bar "http://192.168.0.20/"

Quote
so that it runs LOCALLY (=WITHIN ITS OWN RAM) the EXE which simply creates a report and sends it in html format back to the mobile browser.
If your webserver is configured correctly and can be accessed (be it on your local network or via internet), then:
- your browser on the mobile device will connect to your WAMP server
- WAMP server will 'serve' you a webpage of the main index file (or php)
- you need to request the url http://your.webservers.ip.address/temp/runmyexe.php
- The WAMP server will invoke your executable, will wait for it to finish executing and finally echo back to your chromium browser the words "hello world" (according to rvk's latest php script example).

In case your program produced a new file on disk then you should be able to 'connect' to that file, or as rvk suggested you could output that directly so that your chromium browser shows the contents of the file directly.

Also i have no clue as of what you are trying to accomplish with having the same .exe stored on your mobile device.: you wanted the .exe that is stored on the server to be executed on the server, inside the memory of the server and that is exactly what rvk is trying to accomplish for you (assuming that everything went allright).

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Run windows exe on remote pc
« Reply #24 on: April 05, 2016, 12:18:47 am »
Thanks again.
Ok in wampserver it works. fine.
Let me clarify.
Presently i do not have anything.
I have a sales program (mine) in a client place.
It resides on the one PC it has. No routers.
So the PC has the exe wich writes a report to a text file in his PC.
He wants to be able to see his sales any time he wants when travelling using his
mobiles (varous operating system).
Hi has a fixed IP.
At the moment I am not concerned too much with the further details of the php.
For now lets say he wants to simply create a text file (the report) that my program creates, anytime he whishes from his mobiles. (Say, it will read them later, at his PC)
So Do I have to install a wampserver on his PC?
I thought i could access the php on his PC by typing in the mobile browser
"149.221.62.4//runmyexe.php".
Is that (or similar) something feasible?

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Run windows exe on remote pc
« Reply #25 on: April 05, 2016, 12:42:11 am »
Ah, the plot thickens  :D

Quote
- I have a sales program (mine) in a client place.
- It resides on the one PC it has. No routers.
- So the PC has the exe wich writes a report to a text file in his PC.
- He wants to be able to see his sales any time he wants when travelling using his mobiles (varous operating system).
- Hi has a fixed IP.
- For now lets say he wants to simply create a text file (the report) that my program creates, anytime he whishes from his  mobiles. (Say, it will read them later, at his PC)

Quote
So Do I have to install a wampserver on his PC?
No, for your example being detailed now: it is not an absolute requirement. I would even vote against it for this 'simple' example.

Quote
I thought i could access the php on his PC by typing in the mobile browser "149.221.62.4//runmyexe.php".
Executing PHP on a remote is only possible when running a server that is able to 'serve' php such as WAMP.

You could achieve similar result by running a (background) program listening to a certain port (your client's mobile would have the need for a small program to connect to that background program using the internet and instruct that background task to do its work and send back the results)

If the case is really as simple as you now told (and i understand) then using/installing WAMP on a single client's machine in order to retrieve the output results from a executable is really a bit overkill

Unless you want to 'convert' current client program into a web application using client server architecture, I would suggest either:
1) running a background program at client's machine that can invoke your .exe and return the results or
2) when/if possible build the above functionality inside your clients .exe

In either case the program would need to run 24/7 (in case client needs to be able to "request" 24/7). You might even want to look into the topic of Daemon (or service as windows calls it).

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Run windows exe on remote pc
« Reply #26 on: April 05, 2016, 12:55:17 am »
Thanks molly.
Note though i said "at the moment" i pretend it would  just write a text file on his PC.
I need to need to give an answer to that client. In reality, it will need to receive a response on the mobile in an html table format (but I will dig into it later).
So, to do that i DO need  wampserver installed on his PC, right?
And once he has his wampserver installed
I can access the php file on his computer
whit the call from teh mobile browser
"181.68.73.24//temp/runmyexe.php"?

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Run windows exe on remote pc
« Reply #27 on: April 05, 2016, 12:56:39 am »
What is Inetpub?


Inetpub is the root directory on C: when using IIS7 etc.

epergola

  • Full Member
  • ***
  • Posts: 157
Re: Run windows exe on remote pc
« Reply #28 on: April 05, 2016, 12:58:53 am »
Rvk
 Inetpub is the localhost as set by IIS.
With Chrome it did not even write a text file (lwampserver did).

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Run windows exe on remote pc
« Reply #29 on: April 05, 2016, 01:14:17 am »
Thanks molly.
Note though i said "at the moment" i pretend it would  just write a text file on his PC.

I need to need to give an answer to that client. In reality, it will need to receive a response on the mobile in an html table format (but I will dig into it later).
;-)

Quote
So, to do that i DO need  wampserver installed on his PC, right?
And once he has his wampserver installed
I can access the php file on his computer
whit the call from teh mobile browser
"181.68.73.24//temp/runmyexe.php"?
The answer is both yes and no.

Yes, what you wrote what was quoted above: things can be done that way.

Have you looked at the link i posted ?
Shame, as something based on this is a very neat approach
That small piece of code acts as a html server. Since you 'code' it, you can make it do whatever you want ;-)
(well, except executing .php scripts without having a complete server like WAMP).

^^ adjust that example to not serve only a html page, but:
- first executes your program using standard windows methods of executing another program from shell
- once finished return the result as an html table.

You can check how this works on a local machine:
- run your http server
- start your browser and connect to your localhost using the address bar
- watch what happens ;-)

In the end:
- you run the html server on the pc
- your mobile device uses the browser and connects to the static ip-address using the internet
- the htmlserver 'sees' the connection and istarts your program, waiting for the results.
- once the results are produced, you serve them back to the mobile browser.

Only requires to install the simplehttpserver on the clients machine (with your modifications of course  :P ).

^^ but do note: this way is very insecure and requires some extra security measures. You do not want everyone in the world to be able to connect to that httpserver  :-X

 

TinyPortal © 2005-2018