launching an external program from asp.net

I have a question regarding launching an external application from an asp.net website. Now I think there are security measures in place to prevent that and I know it's not a good practice, but for an intranet site I'm developing it would be incredibly handy to be able to do that.

So far I've found where I can launch an external app if I'm running my server locally (in debug) then it works fine. When I publish the files out to my webserver it no longer works. I know my filepaths are going to be different I imagine, but how can I check if a local file exists? Or can I?

So here's my code:

//the actual launch button on the page
protected void btnLaunchTnet_Click(object sender, EventArgs e)
{
    string tnetpath = "c:\path\tnet.exe";      
    RunProcess(tnetpath, "");
}


private void RunProcess(string cmd, string arguments)
{
    System.Diagnostics.Process p;
    p = new System.Diagnostics.Process();

    p.StartInfo.FileName = cmd;

    if (arguments.Length > 1)
    {
        p.StartInfo.Arguments = arguments;
    }
    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    p.StartInfo.RedirectStandardOutput = false;
    p.StartInfo.UseShellExecute = false;
    p.Start();
}

I also have a quick 'check if this file exists' that I use to disable or enable the button that launches the app

private bool CheckFileExists(string filepath)
{
    FileInfo SetupPath = new FileInfo(filepath);
    return SetupPath.Exists;
}

Answers


I know of a way using ActiveX controls, but then it would work only with Internet Explorer.

Check out this post.


It sounds like you want to launch a program on the client machine.

You can't do that.

If you're on the same domain and using Windows Authentication, you should be able to use impersonation and SysInternals PsExec.exe to launch the process remotely.


I'm only writing what @Slaks wrote but using more words.

When you browse to a web page the following things happen.

  1. The web browser program makes a network connection to the web server program.
  2. The web browser sends an HTTP request to the web server.
  3. The web server processes the information in the HTTP request.
  4. The web server sends an HTTP response back to the browser.
  5. The browser program displays the HTML contained in the HTTP response.

The code in your example is code that will run in step 3 above.

This should be enough information for you to see why you can't launch a process in the way that you want to, but let me know if you don't see it and I'll explain more.


Need Your Help

Advanced CSS layout problem

html css layout border

I want to create a dialog with a title, borders (left, right, bottom) as well as the content. The current source code: