使用 JScript 在 WSH 中提示对话框?

发布于 2024-07-13 14:31:52 字数 150 浏览 4 评论 0原文

如何使用 JScript 在 WSH 中打开提示对话框?

我在文档中找到的唯一弹出对话框是 WshShell.Popup() 方法。 但我需要一种方法来请求用户输入字符串,就像 DOM 中的 window.prompt() 方法一样。

谢谢。

How to open a prompt dialog box in WSH usig JScript??

The only pop-up dialog I've found in the doc is the WshShell.Popup() method. But I need a way to request the user to enter a string, like the window.prompt() method in DOM.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素年丶 2024-07-20 14:31:53

我认为 WScript 对象没有提供这样的方法,但是您可以从在 WSH 上运行的 vbscript 显示输入框。 因此,这是一种可能的解决方案,可以让您从 JS 中调用该 VB 函数! 请注意以下代码片段的文件扩展名“.wsf”。

<!-- Test.wsf -->
<job id="InputBoxInJS">
   <script language="VBScript">
      Function VBInputBox(promptText)
        VBInputBox = InputBox(promptText)
      End Function
   </script>

   <script language="JScript">
      WScript.Echo("Hello from JScript")
      var x = VBInputBox("Enter text")
      WScript.Echo(x)
   </script>
</job>

I think the WScript object does not provide such a method however you can show an input box from vbscript running on WSH. So here is one possible solution which lets you call that VB function from within JS! Please note the file extension for the following code fragment ".wsf".

<!-- Test.wsf -->
<job id="InputBoxInJS">
   <script language="VBScript">
      Function VBInputBox(promptText)
        VBInputBox = InputBox(promptText)
      End Function
   </script>

   <script language="JScript">
      WScript.Echo("Hello from JScript")
      var x = VBInputBox("Enter text")
      WScript.Echo(x)
   </script>
</job>
浅笑轻吟梦一曲 2024-07-20 14:31:53

我知道这个问题已经得到解答,但我不想使用 .wsf 的东西,我也不想加载 Internet Explorer 的开销(正如我看到其他解决方案所做的那样)。 我使用 Google 找到了这个我认为最优雅的解决方案:

http://with-love-from-siberia.blogspot.com/2009/12/msgbox-inputbox-in-jscript.html

关键是使用ActiveXObject“ScriptControl”,设置将语言转换为 VBScript,然后使用 ScriptObject.eval() 函数。 该网站上的示例是独立的。

编辑:对于那些遇到 64 位或换行等错误的人,有一个改进的版本,其中包含有关如何运行它的说明(在 Win7 x64 等系统上)此处

I know this question has been answered, but I wouldn't want to use the .wsf stuff and I also wouldn't want the overhead of loading internet explorer (as I've seen other solutions do). I found this solution using Google that I think is the most elegant:

http://with-love-from-siberia.blogspot.com/2009/12/msgbox-inputbox-in-jscript.html

The key is using the ActiveXObject "ScriptControl", setting the language to VBScript and then using the ScriptObject.eval() function. The example on the site stands on its own.

EDIT: For those encountering an error with 64 bit or line feed, etc., there's this improved version with instructions on how to run it (on systems like Win7 x64) here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文