【问题标题】:Run hide cmd.exe from website (using javascript or VBScript)从网站运行 hide cmd.exe(使用 javascript 或 VBScript)
【发布时间】:2018-09-02 10:53:29
【问题描述】:

为什么以下示例不起作用?另外,我想在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>

【问题讨论】:

  • 你用什么浏览器测试? ActiveXObjects 仅在 IE 11 和 Edge 中受支持
  • 我用firefox测试过,所以只有VBScript可以解决这个问题。
  • 我是说 IE 6+ 和 Edge

标签: javascript vbscript


【解决方案1】:

ActiveX

MDN reference states

注意:Internet Explorer 9 标准模式、Internet Explorer 10 标准模式、Internet Explorer 11 标准模式以及 Windows 应用商店应用或更高版本不支持在远程服务器上创建 ActiveXObject。 p>

因此,除非脚本在您的本地计算机上运行,​​否则代码将不会运行。在 Intranet 的情况下,这似乎有些牵强,其中MDN says:

重要提示:ActiveX 对象可能存在安全问题。要使用 ActiveXObject,您可能需要在 Internet Explorer 中为相关安全区域调整安全设置。例如,对于本地 Intranet 区域,您通常需要将自定义设置更改为“初始化并编写未标记为可安全执行脚本的 ActiveX 控件。”

VBScript

VBScript 是一种专有的 Microsoft 语言,因此只能在 IE 中使用。看到这个Answerlink(来自刚刚引用的答案)指出 VBScript 在 IE 11 中已被弃用,并且在边缘模式下的 IE 11 中将不起作用。

这可能有助于您使 VBScript 即使在 Edge 兼容模式下也能在 IE 11 中工作,

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

【讨论】:

  • 已更新 VBScript 信息
最近更新 更多