从浏览器运行cmd - by JS [英] Run cmd from browser - by JS

查看:398
本文介绍了从浏览器运行cmd - by JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的网页(HTML)打开cmd窗口。我使用JS,但有些不正确,因为当我按下,函数不被调用。

I want to open cmd window from my web page(HTML). I'm using JS but something is not right because when i press, the function isn't called.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
<!--
function runCmd(command, option)
{
    var char34 = String.fromCharCode(34);
    var wsh = new ActiveXObject('WScript.Shell');
    if (wsh)
    {
        command = 'cmd /k ' + char34 + wsh.ExpandEnvironmentStrings(command) + ' ';
        command = command + char34 + wsh.ExpandEnvironmentStrings(option) + char34  + char34;
        if (confirm(command))
        {
            wsh.Run(command);
        }
    }
}
//-->
</script>
</head>

<body>

<input type="button" value="Run!" onclick="runCmd(‘notepad.exe’, ‘%programfiles%\file.txt’);" />
</body>
</html> 

EDIT:
我将其保存为PHP,在FF中有错误:

I saved it as PHP and now i have an error in FF:

ActiveXObject is not defined
[Break on this error] var wsh = new ActiveXObject('WScript.Shell'); 

谢谢!

推荐答案

您必须基本关闭浏览器中的所有安全功能(需要使用各种Internet Explorer才能使用ActiveX)。

You will have to basically turn off all of the security features in your browser (which will need to be some variety of Internet Explorer to use ActiveX).

这种事情是大多数浏览器所不允许的,你能想象如果[互联网上的随机人员]只要通过访问网页就可以在电脑上运行他们想要的东西。

This kind of thing isn't allowed by most browsers, can you imagine if [random person on the internet] could run anything they wanted on your computer just by getting you to visit a web page?

这篇关于从浏览器运行cmd - by JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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