1

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

4

2 回答 2

2

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
于 2012-02-22T20:16:32.263 回答
1

尝试这个

 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
于 2012-02-22T04:20:54.153 回答