Run windows exe on remote pc lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- epergola · 2016-04-03 20:33 Hi Does anyone know how to run an EXE or a DLL on a remote pc from a mobile device? This is the scenario: Have a database  EXE (or a DLL) on A Windows PC. From the mobile, using its browser, I want to send a request (by opening an html file on the PC) to the remote PC 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. Is it possible? Thanks ---------------------------------------------------------------------- Phil · 2016-04-03 23:05 Sounds like you're describing a Web app, where the PC is the server (eg, with an FCGI .exe) and the mobile device is the client (HTML/Javascript downloaded from the PC). -Phil ---------------------------------------------------------------------- epergola · 2016-04-04 05:22 thanks Phil for your reply. I do not excactly what a "web app" is . I hae an EXE that is a dektop application on the PC. when called it makes a report (e.g a list of all customer) and saves to an html file tha it also sends to the requester (mobile). My major problem is how to start an EXE on the PC that runs inside its RAM aND DOES THE JOB. Anything I tried either does nothing or DOWNLOADSW  the EXE. I want it to be run in the PC RAM. Is that possible? ---------------------------------------------------------------------- Thaddy · 2016-04-04 05:35 Phill's answer is correct. What you want is a webserver functionality in the database app or together with the database app on the pc. It then serves the html output to your mobile. On your mobile it can be displayed through the normal mobile browser or through an embedded browser as a web app. You can use a cgi or fastcgi module to do that or even have all server functionality in your database application. All the processing will be done on the PC side and in the PC's memory, except for the request/response script code inside the html. That is handled by the mobile. ---------------------------------------------------------------------- Leledumbo · 2016-04-04 06:43 Exactly, web application is the way to go here. At the worst, if you don't want to implement it, you still have to do raw socket programming, which is much harder, and create protocol to execute the remote app and returning the report you want. That, is not just more complicated, but also a lot harder to secure. ---------------------------------------------------------------------- epergola · 2016-04-04 08:39 Uhm, I guess I cannot explain myself well. My problem is NOT how to RESPOND or RETURN the report to the mobile (at least not know). My problem is this; How can I LAUNCH/START/ EXECUTe the EXE residing on the remote PC from the mobile device using the mobile browser. I want that EXE to be run in the PC's RAM. Forget about the response for a moment. Suppose the EXE on the remote PC simply creates a file  abc.TXT on the PC disk AND THAT IS ALL. No return or response to the mobile. How do I launch/start/execute/run that EXE on the PC from the mobile browser?? THAT is the question. For example. suppose i have an EXE on the PC that simply adds to a text file "Date/Time now is ........".. Well, if I run that EXE on the PC it will do exactly that. I want to run that EXE from a mobile browser and want it to do the same thing on the PC, nothing more Is that possible? Everything I tried  DOWNLOADS THE exe. I do NOT want that, I want it to run the EXE residing on the PC inside the PC RAM AS IF the EXE was run from the PC itself. Is it possible? ---------------------------------------------------------------------- balazsszekely · 2016-04-04 09:08 @epergola To accept a request from a browser(even if you do not wish to respond) you need a web server/web application. Somebody/something must be listen on the other side of the line, otherwise there is no communication. ---------------------------------------------------------------------- Bart · 2016-04-04 09:08 You clarified yourself very well the first time. The answer is still the same as before. Bart ---------------------------------------------------------------------- Leledumbo · 2016-04-04 09:16 Quote from: Bart on April 04, 2016, 11:08:27 amYou clarified yourself very well the first time. The answer is still the same as before. Bart +infinity ---------------------------------------------------------------------- bee · 2016-04-04 09:16 It is very possible, of course. I guess you cannot comprehend the given answers very well. Let me try… Because you want to use mobile browser on a mobile device, then you need to access the .exe through a web server running on the same PC where the .exe resides. To access the .exe through a web server, you need a web app that is triggered by web request (in the form of a URL requested from the mobile browser) to execute the .exe file. Once the .exe file got executed locally on the PC, it will produces a report file (let assume it as a .txt file) that is also created locally. FYI, most web apps basically work like that. Later, if you want to see the .txt file from the mobile device as well, you need the web app to read the .txt file and send its content to the mobile browser. You may make the file downloaded as is, or display the content as HTML output to be rendered on the mobile browser. Your choice. Do you understand? ---------------------------------------------------------------------- serbod · 2016-04-04 10:05 Quote from: epergola on April 04, 2016, 10:39:24 amHow can I LAUNCH/START/ EXECUTe the EXE Web apps is almost a same as Telnet. In Telnet you give command and parameters, it executes on remote machine and return output. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i > dir.exe05.02.2016  17:40               940 README.txt In HTTP you give command and parameters (in URL), it executes on remote machine and return output. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i > GET /cgi- bin/dir.exedir.exe output05.02.2016  17:40             940 README.txt So, web server just show or execute files, that you specified in URL string. ---------------------------------------------------------------------- Thaddy · 2016-04-04 11:48 Quote from: epergola on April 04, 2016, 10:39:24 amMy problem is this; How can I LAUNCH/START/ EXECUTe the EXE residing on the remote PC from the mobile device using the mobile browser. I want that EXE to be run in the PC's RAM. Is it possible? Well, yes, but you still need to have a webserver running on the PC in some form. (even windows remote desktop and similar) The mobile can then request the webserver to start a script or batchfile that starts the executable. Basically everybody here is already putting you on the right track.... ---------------------------------------------------------------------- Zath · 2016-04-04 14:34 Is your exe some unique piece of software ? Can we know what it is as it might have some sort of capability that could help in this instance ? Does something like this run your exe, even on the same pc ? Add shellApi to the uses clause of a simple form and button. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  if ShellExecute(0,nil, PChar('your.exe'),nil,nil,1) =0 then;end; ---------------------------------------------------------------------- Bart · 2016-04-04 15:14 Quote from: Zath on April 04, 2016, 04:34:28 pmAdd shellApi to the uses clause of a simple form and button. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  if ShellExecute(0,nil, PChar('your.exe'),nil,nil,1) =0 then;end;  If that code, when executed from your program on your computer would actually run "your.exe" on my computer, then no zero-day exploits were needed anymore to get control of anyones computer. Bart ---------------------------------------------------------------------- Zath · 2016-04-04 15:52 Quote from: Bart on April 04, 2016, 05:14:15 pmQuote from: Zath on April 04, 2016, 04:34:28 pmAdd shellApi to the uses clause of a simple form and button. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  if ShellExecute(0,nil, PChar('your.exe'),nil,nil,1) =0 then;end;  If that code, when executed from your program on your computer would actually run "your.exe" on my computer, then no zero-day exploits were needed anymore to get control of anyones computer. Bart I realise its not the best piece of code in the world but if his "exe" doesn't even run with that locally, then remotely will likely be a nightmare, even with something better written. I wasn't suggesting he use it as a basis for a programme ---------------------------------------------------------------------- epergola · 2016-04-04 18:48 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 · 2016-04-04 19:12 Quote from: epergola on April 04, 2016, 08:48:08 pmI 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2016-04-04 19:57 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.              . 04/04/2016  02:57 p.m.              .. 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 wamp\www is the local host for wampserver. ---------------------------------------------------------------------- epergola · 2016-04-04 19:58 php 5.4.16 is the version of the php form wampserer ---------------------------------------------------------------------- molly · 2016-04-04 20:08 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 ---------------------------------------------------------------------- rvk · 2016-04-04 20:16 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. ---------------------------------------------------------------------- epergola · 2016-04-04 20:44 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 · 2016-04-04 20:52 Quote from: epergola on April 04, 2016, 10:44:10 pmin 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2016-04-04 21:54 From epergola's first post: QuoteFrom the mobile, using its browser Start your chromium browser, assuming that to be the browser on your mobile device QuoteI 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/" Quoteso 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 · 2016-04-04 22:18 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 · 2016-04-04 22:42 Ah, the plot thickens  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) QuoteSo 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. QuoteI 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 · 2016-04-04 22:55 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 · 2016-04-04 22:56 Quote from: rvk on April 04, 2016, 10:52:35 pmWhat is Inetpub? Inetpub is the root directory on C: when using IIS7 etc. ---------------------------------------------------------------------- epergola · 2016-04-04 22:58 Rvk  Inetpub is the localhost as set by IIS. With Chrome it did not even write a text file (lwampserver did). ---------------------------------------------------------------------- molly · 2016-04-04 23:14 Quote from: epergola on April 05, 2016, 12:55:17 amThanks 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). ;-) QuoteSo, 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 ? Quote from: molly on April 04, 2016, 10:08:01 pmShame, 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  ). ^^ 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 ---------------------------------------------------------------------- rvk · 2016-04-04 23:15 Quote from: epergola on April 05, 2016, 12:58:53 am Inetpub is the localhost as set by IIS. With Chrome it did not even write a text file (wampserver did). I figured as much. But why are you mentioning IIS when your using Wamp? If you want to use IIS, did you install and configure PHP for it? If not... you shouldn't mix up your server-options. And yes, as far as I can see now, if you want to expand and serve your report as a html, Wamp is a fine way to go for that purpose (or install Apache and PHP separately). But like molly explained, if your application can run 24/7 you could also add a small thread listening on port 80 (it any other port and if a remote pc requests a certain page you can run the procedure to create the report and present the file add html through that port (essentially creating a little html-server yourself). If you don't want to do that you can go for the wamp method and do this in PHP. (Edit: also look at the last answer from molly) ---------------------------------------------------------------------- Zath · 2016-04-04 23:33 Sorry rvk, I'm not the OP, I was just mentioning the IIS bit. ---------------------------------------------------------------------- molly · 2016-04-04 23:44 @epergola Seems i have to make small corrections to what i wrote earlier about using/testing the (bare without modifications) simplehttpserver: 1) you need to connect to port 8080 (or change the code to use another port) using your browser and 2) you need f.i. to 'create' a html page in the same directory. If you add the name of the file (for example myview.html) to the url address bar of your browser then you should be seeing the contents of that file. e.g. http://127.0.0.1:8080/myview.html I think rvk made some good points. WAMP is perfectly capable of providing the same functionality with using PHP (and of course far better tested and using much more approved methods). But as rvk perhaps noticed from my writings: it is oh so tempting to copy-paste those couple of lines inside your executable, having all inside the same executable. That is, if you are able to run that app 24/7, if not then you can always use the standalone httpserver approach and invoke your .exe that way. So, i believe that means you have to make some decisions ---------------------------------------------------------------------- epergola · 2016-04-04 23:57 Thanks to both. Molly NO, my.exe does NO run 24/7. It just seats there. When the person with the mobiles wants to run a report, he/she would use the mobile browser and write "109.59.193.23//localhost/runmyexe.php". This would execute the php that in turn execute my.exe. That is what i like to do. IN order to be able to run the php which will run my.exe on the PC, what do i need to have installed on the PC. Suppose I go with wampserver. Just installed is enough? or it has to be in memory all the time in the PC? And this line "109.59.193.23//localhost/runmyexe.php". in the mobile browser  is in the correct format? Thanks ---------------------------------------------------------------------- balazsszekely · 2016-04-05 04:20 @epergola It's perfectly fine to not knowing something, but asking the same question again and again it's a little bit strange. You already got your answers above(if you read the posts carefully). PS: The whole idea of running an exe through a web server is fundamentally flawed. Yes it's possible, but it's not the right approach. ---------------------------------------------------------------------- Thaddy · 2016-04-05 04:39 Quote from: epergola on April 05, 2016, 01:57:19 am"109.59.193.23//localhost/runmyexe.php". localhost is an alias for an ip 127.0.0.1 So that is wrong and won't work Quote from: epergola Suppose I go with wampserver. Just installed is enough? or it has to be in memory all the time in the PC? No there needs to be a webserver running all the time. If you a concerned about resources, don't use a full WAMP stack. Write a small webserver in FPC - simply use the example in fpweb or use something like tinyweb that just does what you want. But you can use a cgi program with almost any webserver, including tinyweb. The cgi can start the executable. (I have fpc running that way as a webservice, tnx l505!) Quote from: epergolaAnd this line "109.59.193.23//localhost/runmyexe.php". in the mobile browser  is in the correct format? No it is not. It is nonsense. See above. You don't seem to get that some complexity is involved. As getmem wrote: it is possible, but not recommended. But as you seem so persistent, read the thread again carefully. All is already explained. ---------------------------------------------------------------------- Leledumbo · 2016-04-05 06:03 It's actually pretty simple and doesn't even require IIS, Apache or the ugly PHP, it can be done in a standalone Pascal web service application. But since the OP lacks web configuration and programming experience, things become harder. Brook example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program ReportWebsite; {$mode objfpc}{$H+} uses  SysUtils,  fpjson,  httpprotocol,  BrookUtils,  BrookAction,  BrookHttpDefs,  BrookFCLHTTPAppBroker,  BrookApplication; type   { TReportAction }   TReportAction = class(TBrookAction)    procedure Get; override;  end; { TReportAction } procedure TReportAction.Get;var  ExitCode: Integer;  EOSE: EOSError;begin  try    ExitCode := ExecuteProcess('/pa th/to/your/report/generating/exe',['parameters','if','required']);    if ExitCode = 0 then      // read the generated report and send as response here,      // either displayed in browser or download, up to you    else begin      EOSE := EOSError.Create('Abnormal termination');      EOSE.ErrorCode := ExitCode;      raise EOSE;    end;  except    on e: Exception do      if e is EOSError then        // generate error response, use (e as EOSError).ErrorCode for analysis      else        // generate generic error response, i.e. use e.Message  end;end; begin  TReportAction.Register('/report');  BrookSettings.Port := 4444;  BrookApp.Run;end. ---------------------------------------------------------------------- Thaddy · 2016-04-05 07:09 I missed a small detail, but nice example. The url to reach that server should be in your case: 109.59.193.23:4444/report. I suspect the OP is not familiar with a service running from a non- standard port. Or am I wrong? Also: brook seems a mature framework by now, but it is a separate download? fpweb is included in the standard distribution. ---------------------------------------------------------------------- Leledumbo · 2016-04-05 07:33 Quote from: Thaddy on April 05, 2016, 09:09:12 amAlso: brook seems a mature framework by now, but it is a separate download? Yes, it's a 3rd party package from silvio. Quote from: Thaddy on April 05, 2016, 09:09:12 amfpweb is included in the standard distribution. Which you can do in it also, only slightly longer code for pure hand coding since the framework is somewhat designed with RAD in mind.