views:

82

answers:

5

I've created an exe file that does some maintainance work on my server. I want to be able to launch it from the website that sits on the server. The exe has to be launched on the server itself and not on the client.

My instincts tell me it's not possible but I've had to check with you guys.

If I need to set certain permissions / security - I can.

UPDATE: Using C#/.NET on IIS .

+1  A: 

A very crude option, Assuming IIS: Change Execute Access from "Scripts Only" or "None" to "Scripts and Executables"

To make this less crude, you should have the executable implement a CGI interface (if that is under your control.

And, if you want to use ASP.NET to add autorization/authentication, the code (C#) to do this would be:

System.Diagnostics.Process process;

var startInfo = New System.Diagnostics.ProcessStartInfo("C:\file.exe")

process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
John Gietzen
Will that execute the exe as if i'm running it from Remote Desktop?
Faruz
Faruz: No, it will execute under the user that IIS runs as; but yes, it will run on the server (obviously).
Noon Silk
@Frauz: You can turn on "Impersonation", to achieve that.
John Gietzen
+1  A: 

It's possible, but almost certainly it's a bad idea. What environment/webserver? You should just need to set the relevant 'execute' permissions for the file.

I really suggest that you don't do this, however, and configure the task to run automatically in the background. The reasoning is that, configured badly, you could end up letting people run any executable, and depending on other factors, completely take over your machine.

Noon Silk
+1  A: 

Depends what language you're using; most server side scripting languages give you a way to exectue shell commands, for example:

$result=`wc -l /etc/passwd`;

executed a unix command from perl.

Erik
Usually there's a function called `system` or back quotes as in answer
vava
A: 

Most web languages (I know at least Java and PHP) allow you to execute a command line argument from within a program.

Kaleb Brasee
+3  A: 

Yes, it can be done, but it's not recommended.

An ideal solution for running maintenance scripts/executables is to schedule them using cron on Unix/Linux systems or using Scheduled Tasks in Windows. Some advantages of the automated approach vs. remote manual launch:

  • The server computer is self-maintaining. Clients can fail and people can forget. As long as the server is running the server will be keeping itself up to date, regardless of the status of client machines or persons.
  • When will the executable be launched? Every time a certain page is visited? What if the page is refreshed? For a resource-intensive script/executable this can severely degrade server performance. You'll need to code rules to handle multiple requests and monitor running maintenance processes. Cron & scheduled tasks handle these possibilities already.
pygorex1
It is a scheduled task, but I want to be able to launch it remotely in certain cases. It is a special case and will not be used normally.
Faruz