Html 从本地网页运行程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5422093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:33:50  来源:igfitidea点击:

Run a program from a local webpage

htmlwindows-7executable

提问by 0plus1

I'm trying to use a webpage as an entry point for a kiosk. The html will be run in local, I need two things:

我正在尝试使用网页作为自助服务终端的入口点。html 将在本地运行,我需要两件事:

<a href="c:\Users\Admin\Documents">...

Which works like a charm

这就像一个魅力

And..

和..

<a href="c:\Program Files\Windows Live\Mail\wlmail.exe">...

(program just an example, all programs are the same)

(程序只是一个例子,所有程序都一样)

Which works but.. it prompts to download the file then you are prompted to start it.. Is there any way to do this directly, like click and bam you opened notepad.exe? Maybe using a java applet?

哪个有效,但是..它提示下载文件,然后提示您启动它..有没有办法直接执行此操作,例如单击并打开notepad.exe?也许使用java小程序?

Thank you

谢谢

Thank

谢谢

EDIT:

编辑:

I know it can't be done remotely, I'm talking about local files. The file will be accessed as c:\myhtml.html And will open ONLY already installed files, nothing from the web.

我知道它不能远程完成,我说的是本地文件。该文件将被访问为 c:\myhtml.html 并且只会打开已经安装的文件,不会来自网络。

采纳答案by oprimus001

If i get your question right , the closest thing to get what you want would be using *.hta which is a HTML Application that runs outside the browser window just like a normal app.

如果我问对了你的问题,最接近你想要的东西是使用 *.hta,它是一个 HTML 应用程序,就像一个普通的应用程序一样在浏览器窗口之外运行。

<script type="text/javascript" language="javascript">
    function RunFile() {
    WshShell = new ActiveXObject("WScript.Shell");
    WshShell.Run("c:/windows/system32/notepad.exe", 1, false);
    }
</script>

Bit more info here: http://www.kunal-chowdhury.com/2010/09/how-to-execute-local-file-using-html.html

这里有更多信息:http: //www.kunal-chowdhury.com/2010/09/how-to-execute-local-file-using-html.html

回答by Vadim Rapp

The right way to implement this is by creating custom protocol in Windows. Details in the MSDN article "Registering an Application to a URI Scheme"

实现这一点的正确方法是在 Windows 中创建自定义协议。MSDN 文章“Registering an Application to a URI Scheme”中的详细信息

回答by Chicna

That's of course a security issue. But that's not the problem, the reason why he want to do that is clearly another problem.

这当然是一个安全问题。但这不是问题,他之所以要这样做,显然是另一个问题。

The question still remains : HOW to execute an external program from CLIENT/SERVER side ?

问题仍然存在:如何从客户端/服务器端执行外部程序?

I found some clues :

我发现了一些线索:

  • ActiveX : Specific to IE, so not very nice,
  • Serverside javascript frameworks, like Node.js : Server side ? I don't even know this framework...^^',
  • Crossbrowser addons which can enhanced possibilities, not my domain here too,
  • In Media player classic, you can make him listen to a port, and then use this to call the program by using specific command urls, pretty nice, but specific to a software.
  • ActiveX : 特定于 IE,所以不是很好,
  • 服务器端 javascript 框架,如 Node.js:服务器端?我什至不知道这个框架...^^',
  • 可以增强可能性的跨浏览器插件,这里也不是我的域,
  • 在Media player classic 中,你可以让他监听一个端口,然后使用它通过特定的命令url 来调用程序,非常好,但特定于某个软件。

I found tons of others cool tutorials, but the work is pretty heavy : Each time i have to discover & learn another technology.

我发现了很多其他很酷的教程,但工作量非常大:每次我都必须发现和学习另一种技术。

回答by Roman Goyenko

No, this is security issue, browsers don't allow it because it could be security risk to run apps without prompt, just by clicking on the link.

不,这是安全问题,浏览器不允许这样做,因为只需单击链接即可在没有提示的情况下运行应用程序可能存在安全风险。

There are several technologies like java WebStart and ASP ClickOnce - they will install the app more or less automatically, signing the application helps too - the messages the user gets look less scary.

有几种技术,如 java WebStart 和 ASP ClickOnce——它们或多或少会自动安装应用程序,签署应用程序也有帮助——用户收到的消息看起来不那么可怕。

回答by Victor Delgado

Correct me if I didn't understand you. If you're running the web page locally (http:\127.0.0.1) and want to execute a program in the same machine, it will depend on the technology that you're using, for example in php you could use exec() to execute a program on user input but it will run on the server side.

如果我不理解你,请纠正我。如果您在本地运行网页 (http:\127.0.0.1) 并希望在同一台机器上执行程序,这将取决于您使用的技术,例如在 php 中您可以使用 exec()在用户输入上执行程序,但它将在服务器端运行。