从浏览器运行 cmd - 通过 JS
我想从我的网页(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>
编辑: 我将其保存为 PHP,现在我在 FF 中遇到错误:
ActiveXObject is not defined
[Break on this error] var wsh = new ActiveXObject('WScript.Shell');
谢谢!
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:
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');
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须基本上关闭浏览器中的所有安全功能(需要使用某种 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?
根据文档:
ActiveXObject
只能在 Internet Explorer 内使用并且只有额外的权限和一些警告消息。您甚至可能会认为,由于它使客户端计算机面临多个安全问题,因此任何其他浏览器都不支持它。According to documents :
the
ActiveXObject
is only usable inside Internet Explorer and 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.