如何在客户端运行程序或批处理文件?

发布于 2024-07-21 00:08:06 字数 281 浏览 3 评论 0原文

如何在客户端运行批处理文件? 一个exe文件? 只是为了在客户端打开预装程序吗?

[编辑]

关于ActiveX,我尝试过,

    var activeXObj = new ActiveXObject("Shell.Application");
    activeXObj.ShellExecute("C:\\WINDOWS\\NOTEPAD.EXE", "", "", "open", "1");

但这不起作用。 有什么建议么?

How can I run a batch file on the client side? An exe file? Just to open pre-installed program in client side?

[Edit]

Regarding ActiveX, I tried

    var activeXObj = new ActiveXObject("Shell.Application");
    activeXObj.ShellExecute("C:\\WINDOWS\\NOTEPAD.EXE", "", "", "open", "1");

but this doesn't work. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

小猫一只 2024-07-28 00:08:06

来自 JavaScript? 你不能。 这是一个安全风险。 想一想 - 您希望每个网站都能够在您的 PC 上运行程序吗?

From Javascript? You can't. It's a security risk. Think about it - would you want every website to be able to run programs on your PC?

浪菊怪哟 2024-07-28 00:08:06

您的意思是使用 JavaScript 通过浏览器窗口启动外部程序? 你不可能这么做! 这真是一个该死的安全黑洞!

You mean launch an external program thru a browser window using JavaScript? No way you can do that! That's a goddamn security black hole!

花辞树 2024-07-28 00:08:06
<script language="javascript" type="text/javascript">

    function RunEXE(prog) {
        var oShell = new ActiveXObject("WScript.Shell");
        oShell.Run('"' + prog + '"', 1);
    }     
</script>
<script language="javascript" type="text/javascript">

    function RunEXE(prog) {
        var oShell = new ActiveXObject("WScript.Shell");
        oShell.Run('"' + prog + '"', 1);
    }     
</script>
国际总奸 2024-07-28 00:08:06

如果您确实可以控制客户端,那么您可能需要在客户端安装一些远程守护程序服务,例如 SSH。

附言。 但是,通过您的“服务器代码”调用它。

更新:

不要灰心。 您绝对可以安全地做到这一点。

  1. 首先,您需要在客户端上有一个守护程序服务来处理调用应用程序的任务。 就我个人而言,我宁愿使用 C++ 或 Delphi 构建简单的 rpc-server 作为 windows-service; 但许多其他类型的服务器也可以完成这项工作(SSH、Apache、Telnet)

  2. 然后制作一个网页,允许用户通过正确的身份验证“注册”其服务来调用该服务(密码、安全密钥)< /p>

  3. 当您想从已经存在的客户端上的网页调用您的应用程序时注册后,向您的服务器发出 ajax 调用 (xmlhttprequest)。

  4. 服务器应使用注册信息验证请求的 IP 地址。

  5. 然后使用注册信息向客户端进行远程命令调用。

在某些网络情况下,该方案可能不起作用。 但是,如果您确实可以控制执行环境,那么总会有一些解决方法。

If you really have control on the client, then you may want to install some remote daemon service on the client side, like SSH.

PS. Invoke it through your "server-code", however.

Updated:

Don't be discouraged. You can absolutely do that in safe manner.

  1. First you need a daemon service on the client that will handle the task of invoking your application. Personally, I'd rather build simple rpc-server as windows-service with C++ or Delphi; but many other kinds of server could also do the job (SSH, Apache, Telnet)

  2. Then make a web pages that allow the user to "register" their services with proper authentication to invoke that service (password, security key)

  3. When you want to invoke your application from web-page on the client that's already registered, make ajax call (xmlhttprequest) to your server.

  4. The server should validate the requesting IP address with registered information.

  5. Then make a remote command invokation to the client with the registered information.

There can be some networking situation that this scheme might not work. However, if you really have control on the execution environment then there always be some workarounds.

心碎无痕… 2024-07-28 00:08:06

将客户端重定向到 http://yourserver/batchfile.bat。 在某些浏览器下,这将提示用户运行批处理文件。

Redirect the client to http://yourserver/batchfile.bat. Under some browsers, this will prompt the user to run the batch file.

撩动你心 2024-07-28 00:08:06

如果问题是批处理文件显示在浏览器中,您需要在 HTTP 标头中设置 Content-TypeContent-Disposition,以便提示用户保存 (或运行)文件而不是让浏览器显示它。

如果没有用户的同意,您将无法运行该文件,但这应该不是问题。

查看此问题以了解更多详细信息。

If the problem is the batch file is being displayed in the browser you need to set Content-Type and Content-Disposition in the HTTP header so the user is prompted to Save (or Run) the file rather than have the browser display it.

You won't be able to run the file without an OK from the user but this shouldn't be a problem.

Have a look at this question for a little more detail.

余厌 2024-07-28 00:08:06

基本上,你不能。 如果您需要在客户端启动某些内容,则需要另一种机制,大概是内置了一些安全性的机制。之前的海报提到了 psexec (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx),这显然只有在您拥有适当权限的情况下才有效在目标系统上,并且完全在浏览器之外。

基本上,如果你能够轻松做到的话,你所要求的就是一个很大很大的问题。

您可能会研究 ActiveX,但我不知道现在 ActiveX 对象有什么限制(我知道有限制,但也许您可以在其中工作)。

Basically, you can't. If you need to launch something on the client side, you'll need another mechanism altogether, presumably one with some security built in. A previous poster mentioned psexec (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx), which will obviously only work if you have appropriate permissions on the target system, and which is completely outside the browser.

Basically, what you are asking for is a BIG, BIG, problem if you were able to do it easily.

You might look into ActiveX, but I don't know what limits there are on an ActiveX object these days (I know there ARE limits, but perhaps you can work within them).

长安忆 2024-07-28 00:08:06

出于安全原因,不允许直接这样做。 除了所有其他答案之外,还有另一个想法。

您可以在预安装的程序中构建一个 localhost Rest 服务,并使用 javascript 通过命令或数据来调用它,假设您编写了预安装的程序,并且该服务应该在您调用时运行。 该解决方案在某些场景下有效。

It's not allowed directly, for security reason. Besides all other answers, there is another idea.

You can build a localhost rest service in your pre-installed program and use javascript to call it with command or data, well assuming that you write the the pre-installed program and the service is supposed to be running when you call. This solution works in some scenarios.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文