1

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;
}
2
  • Just noting that you should use @ before the tnetpath string, to escape the backslashes: @"c:\path\tnet.exe" OR "c:\\path\\tnet.exe" Commented Apr 19, 2012 at 18:30
  • Yeah I did notice that I didn't copy that over. Thanks for catching that though. Commented Apr 19, 2012 at 18:35

3 Answers 3

1

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

Check out this post.

Sign up to request clarification or add additional context in comments.

2 Comments

I will look into this. We (unfortunately) primarily use IE so this might work out for us if it's the only way to go. Thanks for the link!
Ok, so this is the route I ended up going and I got it to work the way I need to. Thanks again!
0

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.

1 Comment

Ok. that's something I can look into. Though will that just launch the program as the user in the background or will the program actually pop up for the user? Like say if I wanted to launch a client application of some sort from the website for the user.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.