VBScript 到记事本/写字板

发布于 2025-01-08 01:00:48 字数 72 浏览 0 评论 0原文

我想将 VBScript 的输出实时写入记事本/写字板。最好的方法是什么?我知道 sendkeys,但它要求我解析特殊命令的输入。

I'd like to write output from VBScript to notepad/wordpad in realtime. What's the best way to do this? I'm aware of sendkeys, but it requires that I parse the input for special commands.

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

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

发布评论

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

评论(2

走走停停 2025-01-15 01:00:48

SendKeys 是实时写入第三方应用程序的唯一方法。为什么不使用 CScript 并写入标准输出呢?这就是它的目的。

' Force the script to run in the CScript engine
If LCase(Right(WScript.FullName, 11)) <> "cscript.exe" Then
  strPath = WScript.ScriptFullName
  strCommand = "%comspec% /k cscript " & Chr(34) & strPath & chr(34)
  CreateObject("WScript.Shell").Run(strCommand)
  WScript.Quit
End If

For i = 1 to 10
  For j = 0 to 25
    WScript.StdOut.WriteLine String(j, " ") & "."
    WScript.Sleep 50
  Next

  For j = 24 to 1 Step - 1
    WScript.StdOut.WriteLine String(j, " ") & "."
    WScript.Sleep 50
  Next
Next

SendKeys is the only method for writing to a third-party application in realtime. Why don't you use CScript and write to the standard output instead? That is what it is meant for.

' Force the script to run in the CScript engine
If LCase(Right(WScript.FullName, 11)) <> "cscript.exe" Then
  strPath = WScript.ScriptFullName
  strCommand = "%comspec% /k cscript " & Chr(34) & strPath & chr(34)
  CreateObject("WScript.Shell").Run(strCommand)
  WScript.Quit
End If

For i = 1 to 10
  For j = 0 to 25
    WScript.StdOut.WriteLine String(j, " ") & "."
    WScript.Sleep 50
  Next

  For j = 24 to 1 Step - 1
    WScript.StdOut.WriteLine String(j, " ") & "."
    WScript.Sleep 50
  Next
Next
£冰雨忧蓝° 2025-01-15 01:00:48

试试这个

 Const fsoForWriting = 2

   Dim objFSO
   Set objFSO = CreateObject("Scripting.FileSystemObject")

  'Open the text file
   Dim objTextStream
   Set objTextStream = objFSO.OpenTextFile("C:\SomeFile.txt", fsoForWriting, True)

  'Display the contents of the text file
   objTextStream.WriteLine "Hello, World!"

  'Close the file and clean up
   objTextStream.Close
   Set objTextStream = Nothing
   Set objFSO = Nothing

Try this

 Const fsoForWriting = 2

   Dim objFSO
   Set objFSO = CreateObject("Scripting.FileSystemObject")

  'Open the text file
   Dim objTextStream
   Set objTextStream = objFSO.OpenTextFile("C:\SomeFile.txt", fsoForWriting, True)

  'Display the contents of the text file
   objTextStream.WriteLine "Hello, World!"

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