views:

140

answers:

2

Hi,

i built an intranet on .NET MVC. I'm also building a separate planning tool in Winforms (performance choice). I would now like to 'open' the planning tool from the intranet (IE7) and pass an argument (e.g. Workorder number) so I can display the planning for that specific item. Is this possible?

I have a .application file for the Winforms application. I'm also able to change everything on both the .NET MVC intranet and the Winforms planning tool.

+1  A: 

Yes you can do it.

private string _output = "";

public string Execute()
{
   try
   {
        Process process = new Process();
        process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
        process.StartInfo.FileName = "path to exe";
        process.StartInfo.Arguments = "here you can pass arguments to exe";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        Process currentProcess = Process.GetCurrentProcess();
        process.StartInfo.UserName = currentProcess.StartInfo.UserName;
        process.StartInfo.Password = currentProcess.StartInfo.Password;
        process.Start();
        process.BeginOutputReadLine();
        process.WaitForExit();
        return _output;
    }
    catch (Exception error)
    {
        return "ERROR : " + error.Message;
    }
}
private void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    if (e.Data != null)
    {
        _output += e.Data + Environment.NewLine;    
    }
}

It's a simple example. You can use different threads to read output and errors from exe.

iburlakov
I need to launch the app, not just read output. Thanx for the effort though. +1
Ropstah
+1  A: 

You can't simply call the application from the HTML; that would be a security hole. However, you can have the application register to be able to handle these requests via the registry. You say "no-install", so this might be a problem. Maybe your app could modify the registry on the first load.

Anyway, the app would register to handle a specific protocol (like when you click on an itunes:// or ftp:// link).

Instead you'd have something like:

<a href="planning://3472">View workflow #3472</a>

which then launches your app with the argument specified.

See http://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx . You say IE7, but this should work with other browsers, too, once the protocol is registered.

James S
I can add the protocol handling myself, that's no problem. However, no arguments are received in the application itself... Not even when I run it through the commandline manually. I can only execute MyApp.Application or Setup.exe, and they both don't seem to pass the arguments to the actual application...?
Ropstah
Are you sure the hkey includes the %1?
James S
Yes it does. I found another solution which include passing querystring parameters to the application. This works for me (however not in Firefox ..... ClickOnce isn't working properly in FF).. I like your solution better so thx!
Ropstah