运行 从网站隐藏 cmd.exe(使用 javascript 或 VBScript)

Run hide cmd.exe from website (using javascript or VBScript)

为什么下面的例子不起作用?另外,我想在 createEmptyFile() 函数中隐藏 cmd.exe 的 window。浏览器应该不会阻止此代码:

<!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

MDN reference states:

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. This link(来自刚刚引用的答案)指出 VBScript 已在 IE 11 中弃用,并且在 Edge 模式下无法在 IE 11 中工作。

可能这可以帮助您使 VBScript 即使在 Edge 兼容模式下也能在 IE 11 中运行,

<meta http-equiv="x-ua-compatible" content="IE=10">