如何在输出文本之间添加一行?

How can I add a line between output text?

下一个标题将替换同一行上的上一个标题。结果,最终只有最后一个标题会保留在文本文件中。

我下面的VBScript会发现一​​些更新标题(脚本中="Title")。每个 "Title" 都将显示在输出文件 "c:\Testing\testing.txt" 中。一个标题将一次显示在第一行。命令 "Next" 将调出下一个标题,当上一个标题消失时,该标题将显示在同一行。简单地说,下一个标题将替换第一行的上一个标题。结果,只有最后一个标题最终会保留在文件中。是否可以在两个标题之间添加一个空行,以便所有标题都显示在文件中?

Set Job = CreateObject("Microsoft.Update.Session")
Set Tool = Job.CreateupdateSearcher() 
Set Result = Tool.Search("IsInstalled=0 and IsHidden=0")
For Number = 0 To Result.Updates.Count-1
    Set Title = Result.Updates.Item(Number)

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    outFile = "c:\Testing\testing.txt"
    Set objFile = objFSO.CreateTextFile(outFile, True)
    objFile.Write Title & vbCrLf 
    objFile.Close
Next

我希望标题显示在不同的行而不是在同一行。

Set objFSO  = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("c:\Testing\testing.txt", True)  'True = overwrite existing file
objFile.Close
Set objFile = objFSO.OpenTextFile("c:\Testing\testing.txt", 8)       '8 = For Appending
objFile.WriteLine ("Title")
objFile.WriteLine ("Title2")
objFile.Close

希望对您有所帮助!

我刚刚发现 OpenTextFile8, True 在下面的脚本中都不是必需的,它在我这边有效。

Set Job = CreateObject("Microsoft.Update.Session")
Set Tool = Job.CreateupdateSearcher() 
Set Result = Tool.Search("IsInstalled=0 and IsHidden=0")
Set X = CreateObject("Scripting.FileSystemObject")
Set Z = X.CreateTextFile("Updates_found.txt")

For Number = 0 To Result.Updates.Count-1
Set Title = Result.Updates.Item(Number)
Z.Writeline Title
Next