简体   繁体   English

无法使用 JavaScript 在 .hta 中调用 curl

[英]Unable to call curl in .hta using JavaScript

For some reason I am not able to call curl.exe in .hta using JavaScript.出于某种原因,我无法使用 JavaScript 在 .hta 中调用 curl.exe。 Running the following (just an example) as .hta运行以下(只是一个例子)作为 .hta

<!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript">
            w=new ActiveXObject("WScript.Shell")
            w.run('"C:\\Windows\\System32\\curl.exe" "https://www.google.com" -o t.txt')
        </script>
    </body>
</html>

results in file not found error, though curl.exe definately exists in System32 directory.导致文件未找到错误,尽管 curl.exe 肯定存在于 System32 目录中。 If I, however, call curl.exe located in different directory, that works fine, as well as just 'curl' if I add that directory to PATH.但是,如果我调用位于不同目录中的 curl.exe,则可以正常工作,如果我将该目录添加到 PATH 中,则只调用 'curl'。 Also running eg notepad.exe or fc.exe in System32 directory works.也可以在 System32 目录中运行例如 notepad.exe 或 fc.exe。

I tried also using VBScript to launch curl in .hta but that doesn't work either.我还尝试使用 VBScript 在 .hta 中启动 curl,但这也不起作用。 If I however create .js with但是,如果我创建 .js

w=new ActiveXObject("WScript.Shell")
w.run('"C:\\Windows\\System32\\curl.exe" "https://www.google.com" -o t.txt')

or .vbs with或 .vbs

Set w = CreateObject("Wscript.Shell")
w.Run("""C:\\Windows\\System32\\curl.exe"" ""https://www.google.com"" -o t.txt""")

both work well.两者都运行良好。

So what is the reason for curl not working when called in .hta?那么在 .hta 中调用 curl 不起作用的原因是什么? Is it blacklisted for some (security?) reasons, is there a bug somewhere, or am I just doing something wrong?它是否出于某些(安全?)原因被列入黑名单,某处是否存在错误,或者我只是做错了什么?

EDIT: Tried to call a .bat calling curl.编辑:试图调用 .bat 调用 curl。 Same story: if .bat calls C:\\Windows\\System32\\curl it won't work, when called in .hta, but works when called by .js or .vbs.同样的故事:如果 .bat 调用 C:\\Windows\\System32\\curl 它将不起作用,当在 .hta 中调用时,但在由 .js 或 .vbs 调用时起作用。 Calling SomeOtherDirectory\\curl.exe works.调用 SomeOtherDirectory\\curl.exe 有效。

I finally managed to type the write words to Google and found what was wrong .我终于设法将写的话输入到谷歌并找到了问题所在 HTA files are run by 32 bit mshta.exe, which leads C:\\Windows\\System32 to redirect to C:\\Windows\\SysWOW64 where no curl.exe exists. HTA 文件由 32 位 mshta.exe 运行,这会导致 C:\\Windows\\System32 重定向到不存在 curl.exe 的 C:\\Windows\\SysWOW64。 Replacing System32 with Sysnative made .hta work.用 Sysnative 替换 System32 使 .hta 工作。

w.run('"C:\\Windows\\Sysnative\\curl.exe" "https://www.google.com" -o t.txt')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM