从html-page执行exe-file?

时间:2011-03-31 20:57:01

标签: html exe

我想在点击本地html文件上的链接后启动本地exe文件(不先将其保存到其他位置)。

它需要在IE,Firefox,Chrome或Opera中工作,我不在乎。这只是为了明天的演讲。

5 个答案:

答案 0 :(得分:1)

根本不可能。如果是,它将被视为安全漏洞并被修复。在几个小时内在Firefox上,在几个月内在IE浏览器上。

更新:您可以尝试注册自定义协议:http://openwinforms.com/run_exe_from_javascript.html

但我相信浏览器仍会提示您是否要运行该应用程序。

答案 1 :(得分:1)

我想分享我的经验。

被接受的答复说这是不可能的,但间接是有可能的。

如果要在PC上执行exe,则意味着您在此PC上具有访问权限,并且可以在该计算机上安装exe。

就我而言,我必须通过Web应用程序从3D扫描仪进行3D扫描。一开始似乎不可能。

经过大量研究,我发现我们可以通过javascript发送套接字消息。

这意味着,如果我们有一个侦听特定端口的应用程序,则它可以与网站进行通信。

让我们解释一下我是怎么做到的。

在我的Web应用程序中,我创建了一个像这样的javascript方法:

    function openCapron3DScanner(foot) {
      $("#div-wait").show();

      //Creates a web socket pointed to local and the port 21000
      var ws = new WebSocket("ws://127.0.0.1:21000");
      ws.onopen = function () {

      //Sends the socket message to the application which listens the port 21000  
      ws.send(foot + "-" + @ProjectHelper.CurrentProject.Proj_ID);

     };
      ws.onerror = function myfunction() {
          $("#div-wait").hide();
          alert("Erreur connection scanner.");
      }

      ws.onmessage = function (evt) {
        //Receives the message and do something...
        var received_msg = evt.data;
         if (received_msg == "ErrorScan") {
            alert("Erreur scan.");
         }
         else {
            refreshCurrentProject();
         }
     };
    ws.onclose = function () {
        $("#div-wait").hide();
    };
};

然后我创建了一个Windows窗体应用程序,该应用程序侦听localhost和端口21000。 该应用程序是隐藏的,仅显示在图标栏中。 唯一要做的就是在第一次启动时通过代码在Windows启动时添加应用程序,以确保将在Windows下一次重新启动时执行该应用程序并监听端口。

      private static WebSocketServer wsServer;
      static WebSocketSession LastSession;

      private void Form1_Load(object sender, EventArgs e)
      {
        wsServer = new WebSocketServer();
        int port = 21000;
        wsServer.Setup(port);

        wsServer.NewMessageReceived += WsServer_NewMessageReceived;

        wsServer.Start();
      }



    private static void WsServer_NewMessageReceived(WebSocketSession session, string value)
    {
        if (value.StartsWith("ScanComplete-"))
        {
            //If the scan is ok, uploads the result to the server via a webservice and updates the database.
            UploadImage(value);

            //Sends a confirmation answer to the web page to make it refresh itself and show the result.
            if (LastMacSession != null)
                LastMacSession.Send("ScanComplete");
        }
        else if (value == "ErrorScan")
        {
            //If the C++ application sends an error message
            if (LastMacSession != null)
                LastMacSession.Send("ErrorScan");
        }

        else//call the 3D Scanner from the web page
        {
            LastSession = session;//Keeps in memory the last session to be able to answer via a socket message

            //Calls the C++ exe with parameters to save the scan in the related folder.
            //In could be don in this same application if I had a solution to consume the scanner in C#.
            var proc = System.Diagnostics.Process.Start(@"C:\Program Files\MyProjectFolder\MyScannerAppC++.exe", projectID + " " + param);
        }
    }

我希望这会有所帮助。

答案 2 :(得分:0)

使用System.Diagnostics.Process.Start()方法。

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start("notepad.exe");
    }

你将不得不使用C#,但由于这是你的帖子,它应该工作。如果文件不在加载到内存中的环境路径中,您还需要完整路径。

对于“常规链接”,您仍然需要将其放在ASPX页面中.....

< a href =“test”onclick =“<%System.Diagnostics.Process.Start(”notepad.exe“);%>”>点击我< / a>

我们现在变得非常生气。

答案 3 :(得分:0)

您无法在网站上运行exe文件。 (首先,如果它是Linux服务器,exe文件将无法在其上运行,其次,如果您在Windows服务器上,您的主机将立即终止该程序。并且可能会终止您的帐户。)

该链接(假设它是Play Now!)将允许您的用户下载该文件。 (C:\ Program Files \ World of Warcraft \存在于您的计算机上,但它在Web服务器上不存在。)

答案 4 :(得分:0)

您可以在本地操作系统上设置自定义协议(如果是Windows),请使用regedit。 查看thisthis

然后,您创建一个简单的HTML页面,并放置一个链接,如下所示:

<a href="presentation://C:\\start.exe/">Start!</a>

鉴于您注册了自定义&#34;演示文稿&#34;协议,并在注册表中正确配置,应用程序应在您单击该链接时启动。

相关问题