Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch a program from ASP.NET C#

I have a program (I created) and I want to start it on the server when the webpage loads.

Here is the code I have

public partial class _Default : System.Web.UI.Page
{
    Process app = new Process();
    protected void Page_Load(object sender, EventArgs e)
    {
        app.StartInfo.FileName = @"D:/Path to /My/Program to be run.exe";
        app.Start();
    }
}

Right now the application is 'run' however it crashes instantly. If I just run the application (by double clicking the exe) it runs and everything is fine.

anyone see if i'm missing something here?

like image 821
rlemon Avatar asked Aug 26 '11 19:08

rlemon


People also ask

What is ASP.NET c#?

ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites. It allows you to use a full featured programming language such as C# or VB.NET to build web applications easily.

How do I open .NET core web application?

Run the ASP.NET Core Application: To run this web application, click on IIS Express or press F5 (with Debug) or Ctrl + F5 (without Debug).


1 Answers

You could use ProcessStartInfo.

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @"D:/Path to /My/Program to be run.exe";
psi.WorkingDirectory = IO.Path.GetDirectoryName(psi.FileName);
Diagnostics.Process.Start(psi);
like image 75
Smur Avatar answered Sep 27 '22 20:09

Smur