为什么下面的例子不起作用?另外,我想在createEmptyFile()
函数中隐藏cmd.exe的窗口。浏览器可能不应该阻止此代码:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Default Page Title</title>
</head>
<body>
<script type="text/javascript" language="javascript">
function pingItjs(ipAddress) {
var oShell = new ActiveXObject("wscript.shell");
oShell.Run("cmd.exe /k ping" + ipAddress);
}
function createEmptyFile() {
var oShell = new ActiveXObject("wscript.shell");
oShell.Run("cmd.exe /c cd %tmp% && echo hello > EmptyFile");
}
</script>
<script language="VBScript">
function pingIt(ipAddress)
set WshShell = CreateObject("WScript.Shell")
WshShell.Run("cmd.exe /k ping " & ipAddress)
end function
</script>
<a href="javascript:pingItjs('216.58.215.78')">ping</a>
<div onclick="call pingIt('216.58.215.78')">ping</div>
<a href="javascript:createEmptyFile()">ping</a>
</body>
</html>
最佳答案
ActiveX
Note: Creating an ActiveXObject on a remote server is not supported in Internet Explorer 9 standards mode, Internet Explorer 10 standards mode, Internet Explorer 11 standards mode, and Windows Store apps or later.
因此,除非脚本在本地计算机上运行,否则代码将不会运行。在内联网的情况下,这似乎可以有所延伸,其中 MDN says :
Important: ActiveX objects may present security issues. To use the ActiveXObject, you may need to adjust security settings in Internet Explorer for the relevant security zone. For example, for the local intranet zone, you typically need to change a custom setting to "Initialize and script ActiveX controls not marked as safe for scripting."
VBScript
VBScript 是 Microsoft 专有语言,因此仅适用于 IE。看这个Answer 。这个link (来自刚刚引用的答案)指出 VBScript 已在 IE 11 中弃用,并且无法在 Edge 模式下的 IE 11 中工作。
这可能会帮助您使 VBScript 在 IE 11 中工作,即使在 Edge 兼容模式下也是如此,
<meta http-equiv="x-ua-compatible" content="IE=10">
关于javascript - 从网站运行 hide cmd.exe(使用 javascript 或 VBScript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52136282/