我想从我的网页(HTML)打开cmd窗口。我使用JS,但有些东西不对,因为当我按下时,函数不会被调用。从浏览器运行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');
谢谢!
在什么浏览器中?您正在使用IE浏览器,并且该页面位于可信网站中,对吗? (或任何需要IE浏览器运行这样的潜在危险的东西) – 2010-11-18 13:42:32
在IE和FF ...是的,值得信赖的网站。 – Ronny 2010-11-18 13:43:59
而你虽然'eval()'是邪恶的... – 2010-11-18 13:44:30