Nick
Nick

Reputation: 35

How to run a server-side application via ASP.Net(C# or VB)

I wanted to build a front end web page so that I can start and stop various programs on my server remotely. I know that Shell will open something locally, but how can I make an ASP.Net page which activates programs server-side? Googling got me the "Shell" method, but I don't think that works server-side. Any ideas?

Upvotes: 0

Views: 3448

Answers (1)

Harry Steinhilber
Harry Steinhilber

Reputation: 5239

Take a look at the System.Diagnostics.Process class. It can allow you to start and stop an executable on the server.

You would have to impersonate an account that has sufficient privileged to run the application, though. You can use the UserName and Password properties of the System.Diagnostics.ProcessStartInfo object that you pass to Process.Start.

Edit

For an example, you could do the following:

var startInfo = new ProcessStartInfo("C:\MyServerApp.exe", "/A /B /C");
startInfo.UserName = "LocalUser";
// It's a bad idea to hard code the password in the app, this is just an example
startInfo.Password = "SomePass";

var process = Process.Start(startInfo);

// Not a good idea to wait in a web app, but you can until the process completes
process.WaitForExit();

Upvotes: 1

Related Questions