PHP code located on linux server needs to run windows .exe - c#

The project I am apart of uses a Linux server to host our code. The API I was provided to use was only usable within C#, so currently I have a Windows executable that performs a small task. This executable is called to execute by a PHP file from a website.
Currently, I am attempting to run the file remotely from the Linux server by letting the Windows executable reside on a server running Windows and doing a remote execute call using http://php.net/manual/en/features.remote-files.php, but even if this works, it doesn't seem like a safe or correct way to do things.
A senior suggested I use an IIS server to call it securely, but I am not familiar with this. Before continuing, I thought it would be responsible to ask: is there is a way to have this PHP code residing on a Linux server to run a Windows executable without having to call a remote Windows server for it to run on.

You could write a small web API to run on your Windows server, that after authenticating the request will allow you to execute certain commands locally. Your application running on the linux server could then send requests to this web API and either wait for the results to be returned in that request, or have the Windows server send the results back in an API request later.
The other option which is arguably simpler... just host the entirety of your application on the Windows server.

Related

Run desktop app via WEB app

I have desktop application that can be installed on the users computer with "setup" msi file like any other application.
I'm developing web application and I need somehow to integrate the desktop application with the web application. Web application is developed using PHP (desktop application is developed using C#), and when clicking on one button on the web application, the desktop application needs to be launched.
Is there a way of doing this? I was thinking about a few scenarios:
-Maybe if possible to install the app directly on the server and to launch it from there?
-Maybe to be required the user to have the app installed on his computer and to call the app from there?
If possible I would prefer to not use the second approach because it's better if the third party to not be involved - it will be more user friendly if the application is launched directly. But any help will be appreciated because at this point I'm not sure if that is possible to be done at all.
You can install app at server an run it with exec() or "`" operator - but to control gui of app you need to use some like autoit ant etc.
If you ultimately decide to require your users to have the client application installed and expect majority of the users to be on Windows, you could register your application to handle specific scheme and parse its command line when started. More on this here:
http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
You'd register a custom scheme and then intercept in in the application's command line arguments. The whole URL will be passed as an argument, e.g.:
myapp://parameter1,parameter2
The browser will mostly ask whether or not the user trusts the application to handle this scheme with an option to remember this setting.
If you don't have access to the source code of the client application, you can develop a middleware, some sort of a launcher that handles the URL and then runs the client application after maybe modifying some configuration files based on the URL or otherwise controlling the third-party application to do as you with.
As for solution #1, I don't think C# matters if your application can run on Mono, so you should be able to just run it from PHP. However, this probably won't work on web hosting and you will have to get a VPS for that.
There are very good (security) reasons why it is hard to launch client-side processes from web browsers.
Do you have access to the source code of the C# app? If so, you could consider modifying it to take advantage of Microsoft ClickOnce deployment.
Some references:
http://msdn.microsoft.com/en-us/library/t71a733d.aspx
http://msdn.microsoft.com/en-us/library/t71a733d(v=vs.80).aspx
http://msdn.microsoft.com/en-us/library/6ae39a7c.aspx
http://www.codemag.com/Article/0902031
Here's an old article on deploying WinForms applications via ClickOnce with Visual Studio 2005: http://msdn.microsoft.com/en-us/library/ms953320.aspx
It can possibly be done with IIS but it can be cumbersome setting it up to run as the current user, especially since it would probably also need to run elevated for an app that needs to attach to the current user's desktop.
Easiest is to install a Windows LAMP distro (like WAMP: http://www.wampserver.com/en/) and then run the httpd.exe directly from an elevated (Admin) command prompt; do not run apache as a service!
Once you do this performing and exec("command"); call in php will bring up a desktop app as if it was invoked from an admin command prompt. Obviously you need to set up the apache server to be accessible from outside the local system, etc.

Deploy a backend application on a Windows Server

I'm making an application in C# with VS 2012 that checks a database every 15 seconds and perform some actions when it finds data. Right now I've created a Console Application so I can debug it easely but during relese this application needs to run in a IIS server.
How can I do that? I've read this question but it looks like some sort of workaround because to run it I need to perform these steps. Right now I'm reading the docs about Windows Service Application, Is this the right way?
EDIT Sorry but I've never used Windows server before, so as people pointed out IIS is only a web server, the thing I need to do is run my application in a Windows Server environment
IIS is a web-server and accordingly it should be used for hosting web applications.
Develop a windows service which does the job of checking the database in intervals and invoke a web service (which you can host in IIS)
If your application is performing some data query and manipulation on the server then I would recommend the approach to host it in a windows service.
Some advantages to this are:
The service will start and run independently of a user logging into the server.
You can configure the service to recover should it experience an exception (ideally not!).
The service will start automatically (if configured) when the server restarts.
You can configure which user group (or user) the service should run under so you have a more granual approach to security.
As it's running as a seperate process, you can monitor its memory and processor utilisation.
Debugging is slightly more cumbersome but not difficult, one approach I've used is to install the service locally, start it and then attach to it via the debugger. This question describes another approach I've also used.

Creating a Web Server container to emulate an IIS server

Okay, I'm a very green developer (co-op student) so I'll try my best to make sense. Currently I have a web application (call it "Updater") that is an aspx and runs through IIS. My boss has asked my to look into creating a program (exe or command line) that can run the app through created encapsulated web server that can act like IIS. This is so that I can run the exe during an installer procedure on a client's machine so that the updater can configure the client's program.
So Far I've looked into sources upon sources on how to create a self hosted web server to handle a web app and I've managed to do the following:
-Create a command line server hosted at a given port #######.
-Use a StreamReader to read an html file
-Use HttpResponseMessage to set the Content to this html page.
Obviously this is very rudimentary, but I couldn't understand how to switch the app over to the server I created rather than the IIS.
Any help ont he matter would be appreciated, like I said I'm still quite new.
You can use OWIN to self host from within a console application.
Look for 'Self-Host OWIN in a Console Application' in the following link:
http://www.asp.net/aspnet/overview/owin-and-katana/getting-started-with-owin-and-katana
You need to start you self host server with the address your app is trying to contact. If your IIS is running with the default settings it should be http://localhost:80. Before you start the self host server you need to shut down your IIS website that is running on port 80. Two applications can not listen on the same port at the same time.
What you ask is a redistributable web server for ASP.NET. So, you might find interesting the UltiDev Web Server, formerly known as Cassini web server.
From their website:
UltiDev Web Server Pro (UWS) is an advanced, redistributable web server for Windows that can be use as a regular web server to host web sites and ASP.NET applications, or packaged with your ASP.NET web application and installed on your customers' systems along with your web app or site.

Client/Server Application That Can Deploy Client From Server

I have a client-server application written in c#. I am hoping someone can give some direction on where to look in order to set it up where a user could connect to the server from their workstation, most likely through http but that's not a requirement, and download the client. The mechanism would need the following features:
Check for updates on client startup and automatically apply them.
Allow multiple clients (connected to different servers) to download on the same machine
Client can be downloaded by a non-local admin
Possibly install any prerequisites needed on the workstation
I currently use ClickOnce but it isn't quite working out. Currently the server sits in IIS and uses WCF services.

C# - command line application calls

I have done plenty of C# shell command calls, apps, batch files etc. The other day I was asked if it would be a problem if an executable that I currently run from my web site app, would move to another server on our intranet.
In other words the web site app and the executable that I am running through Process.Start(...) are located on the same box currently - all good there. Now there is a wish to separate the two on two different servers.
I done a few futile attempts to execute an app (located on server B) from server A (where the web site resides).
Is there a way that I have not run cross yet to do this ?
Thanks
PsExec is one way with minimal coding. Using System.Diagnostic.Process, you can call this command:
psexec \\ServerB (path)\myapp.exe arg0 arg1 ...
To control the processes of server A by running an application on server B, you would need an application running on server B that would get controlled remotely somehow.
As an example, let's say server A runs unix, so you could write a application that would connect to server A using ssh, authenticate and then control the processes and whatnot like you do in a shell. If server A does not allow ssh connection, you could write your own application that would be running on server A listening to some connection and commands that would come from an application in server B.
It's quite hard to understand what are your current settings and why would you even want to switch the application from server A to server B, so a little more information would wield you a better answer.
Austin's PSExec approach is probably the easiest approach to executing an EXE on a remote machine, but you may want to consider a potentially more robust solution:
You could modify your command-line app to run as a service and to respond to requests for work and/or data via a WCF (binaryXML/TCP or XML/HTTP) call.

Categories