How can I get a program on a client machine to run from an ASP.NET page?

天大地大妈咪最大 提交于 2019-11-29 19:25:55

问题


I have an app that I'm trying to run on an intranet. On my machine it worked great (famous last words) but when I put it up to the server, it didn't work. As soon as I saw the "the system cannot find the specified file" error, I figured it had to be something with trying to run a program that's on a client machine.

Yes, it would be a security nightmare if any app in a browser could run an executable on a client machine. Is this any different for intranet? The few computers it would run on all have the same version of IE and .NET that it will run on, and they all have the required .exe to run.

Here's an overview of the project:

  • An employee and a participant walk into a room containing a computer.
  • The employee opens my web app and looks up the person's ID (this part works)
  • Clicking on "record" should perform a hidden launch of an already-installed program, which begins recording.
  • When finished, the employee clicks finish (or the app times out) and the file is saved.
  • File gets uploaded to server.
  • The employees lack technical experience, so my objective is to pretty much have a website for them to go to where there is little more than a box to get the participant ID and two giant "RECORD" and "STOP" buttons

Can anyone help me out on how to do this (or at least let me know it's not feasible)?


回答1:


If you put your site in the IE Trusted or Intranet zone, the following Javascript will work just fine. I use this one internally to link our PC support DB search to our remote screen control software:

<script type="text/javascript" language="javascript">
    function runDameWare(strHostname, blControl) {
        var objShell = new ActiveXObject("Wscript.Shell");
        var strCommand = "C:\\Program Files\\Dameware\\dwrcc.exe -c: -h: -m:";
        strCommand += strHostname;
        if (blControl) {
            strCommand += " -v:";
        }
        objShell.Exec(strCommand);
    }
</script>

My understanding is that uploading the results of your work in the local program to the web server can be accomplished using the HttpWebRequest class, as shown in this article:

http://forums.asp.net/p/1482778/3464854.aspx


Edit: This is how I call the above function. Basically I'm just rendering a plain <a> element with the onclick attribute. There's probably a cleaner way to do it, but it works:

Markup:

<asp:TemplateField>
    <ItemTemplate>
        <%# RenderDameWareLinks(Eval("ResourceName"))%>
    </ItemTemplate>
</asp:TemplateField>

Code:

Protected Function RenderDameWareLinks(ByVal strHostname As String) As String
    Dim strFullLink As String = String.Empty
    Dim strViewLink As String = String.Empty
    strFullLink = "<a onclick=""runDameWare('" & strHostname & "', false);"">"
    strFullLink &= "<img alt=""Connect using DameWare"" src=""Image/dameware1.gif"" style=""padding: 2px;"" />"
    strFullLink &= "</a><br/>"
    strViewLink = "<a onclick=""runDameWare('" & strHostname & "', true);"">"
    strViewLink &= "<img alt=""Connect (View Only) using DameWare"" src=""Image/dameware2.gif"" style=""padding: 2px;"" />"
    strViewLink &= "</a>"
    Return strFullLink & strViewLink
End Function



回答2:


One idea: You can register a Protocol handler to launch your app with the required parameters.




回答3:


There are a couple of ways to do this. One doesn't violate security (much).

You can download a file with a particular file type. That file type can be associated to the client program, so after clicking "ok" to download the file, the client program would launch. The downloaded file may or may not contain some data like the id of some object.

The alternative would be to resort to ActiveX, which does have security implications.




回答4:


Since the machine already needs to have this "hidden" program installed, why not just write a native application and install that and have the employee run that instead of your web application?



来源:https://stackoverflow.com/questions/7177145/how-can-i-get-a-program-on-a-client-machine-to-run-from-an-asp-net-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!