Javascript 从浏览器运行 cmd - 由 JS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4215339/
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
Run cmd from browser - by JS
提问by Ronny
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.
我想从我的网页(HTML)打开 cmd 窗口。我正在使用 JS 但有些地方不对,因为当我按下时,没有调用该函数。
<!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:I saved it as PHP and now i have an error in FF:
编辑:我将它保存为 PHP,现在我在 FF 中有一个错误:
ActiveXObject is not defined
[Break on this error] var wsh = new ActiveXObject('WScript.Shell');
Thank you!
谢谢!
回答by Gareth
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).
您基本上必须关闭浏览器中的所有安全功能(需要使用某些 Internet Explorer 才能使用 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?
大多数浏览器都不允许这种事情,你能想象如果[互联网上的随机人]可以通过让你访问一个网页来在你的计算机上运行他们想要的任何东西吗?
回答by AmiNadimi
According to documents:
根据文件:
This object is a Microsoft extension and is supported in Internet Explorer only...
此对象是 Microsoft 扩展,仅在 Internet Explorer 中受支持...
the ActiveXObject
is only usable inside Internet Explorerand only with additional permissions and several warning messages. you might even consider that as it exposes client computers to several security issues, it is not supported by any other browsers.
在ActiveXObject
只有内部使用的Internet Explorer并只与额外的权限和几个警告信息。您甚至可能会认为,由于它使客户端计算机面临多个安全问题,因此任何其他浏览器都不支持它。