Faruz
Faruz

Reputation: 9959

Running an .exe from a website

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.

Upvotes: 4

Views: 345

Answers (5)

leepowers
leepowers

Reputation: 38298

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.

Upvotes: 3

Kaleb Brasee
Kaleb Brasee

Reputation: 51925

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

Upvotes: 0

Erik
Erik

Reputation: 20712

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.

Upvotes: 1

Noon Silk
Noon Silk

Reputation: 55072

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.

Upvotes: 1

John Gietzen
John Gietzen

Reputation: 49544

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();

Upvotes: 1

Related Questions