从HTML页面调用.bat脚本 [英] Invoke a .bat script from HTML page

查看:462
本文介绍了从HTML页面调用.bat脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个客户可以在Windows Server上安装的软件,并且写了一个HTML页面作为安装指南.如何在HTML页面上创建一个链接,该链接将以管理员身份调用我的.bat脚本..bat脚本将为客户处理安装.HTML页面将作为文件运行,没有任何服务器(包括本地主机)..bat脚本,html页面和二进制文件将位于同一文件夹中.该文件夹可能位于Windows服务器上的任何位置(我不知道客户将文件夹放置在何处).

I've written a software that customers will install on Windows Server, and I wrote a HTML page for installation guide. How do I create a link on HTML page that will invoke my .bat script as an administrator. The .bat script will handle installation for customers. HTML page will be run as a file, that is without any server (including local host). The .bat script, html page, and binary will be in the same folder. The folder could be anywhere on the Windows server (I don't know where customers will place the folder).

推荐答案

在Internet Explorer中:

In internet explorer:

file://mydirectory/myfolder/mybatchfile.bat

大多数浏览器不允许使用此功能,因为它给网页上的链接运行本地文件带来了巨大的安全风险.它们中的大多数都具有禁用该安全功能的扩展.不过,我没有测试它们中的任何一个是否起作用.即使发生这种情况,.bat运行也会像下载一样发生.浏览器将下载" .bat文件,然后为用户提供保存或运行该文件的机会.除非您的批处理文件在文件本身中进行管理提升,否则用户将必须以管理员身份手动运行它.

Most browsers don't allow this functionality because it poses a huge security risk for a link on a web page to be able to run local files. Most of them have extensions that disable that security feature. I haven't tested any of them to see if they work, however. Even when this happens, however, the .bat run will happen like a download. The browser will "download" the .bat file, then give the user the opportunity to save it or run it. Unless your batch file is doing the administration elevation within the file itself, the user will have to manually run it as administrator.

请记住,这些保护措施之所以存在是有原因的,绕开它们并不是一个好主意.但是,最终还是无法使浏览器自行执行该代码.(非常感谢!)有更好的方法可以完成这些任务.

Please keep in mind that these safeguards exist for a reason, and going around them is not a good idea. At the end of the day, however, there is no way to make the browser execute that code on its own. (Thankfully so!) There are better ways of accomplishing these kinds of tasks.

如果您想提供有关您要完成的工作的更多详细信息,我相信我们可以为您做想做的事情提供更安全的选择.

If you wanted to provide more details on what you are trying to accomplish, i'm sure we could come up with a more secure of doing what you want to do.

这篇关于从HTML页面调用.bat脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆