javascript - 从网站运行 hide cmd.exe(使用 javascript 或 VBScript)

标签 javascript vbscript

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

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 。这个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/

相关文章:

使用 paise 支持将印度货币数字转换为单词的 Javascript 函数

datetime - VBScript 中的日期格式 - 用 0(零)作为月份前缀,例如07 而不是 7

javascript - 获取完整的实际 html 页面源,包括框架集

javascript - 一次使用两个或多个元素迭代数组

javascript - Chrome 按键排序对象

windows - 从 HKEY_USERS 值获取用户名

c - 如何用windows主机文件响应请求?

javascript - 使用单个 html 文件显示本地文件夹中的所有图像

javascript - 检查 DOM 元素的 Node.js 模块

javascript - 优化 Sequelize 中相关表的查询