VBScript到记事本/写字板

时间:2012-02-22 00:07:01

标签: vbscript notepad output-redirect

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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