2

I need create one script for open one file (Server.txt → content all servers names) and create logfile with ServerName (example: Server1.txt). After that I need WriteLine in this logfile result of the script retrieve registry values.

I have one script working retrieve all registry values but I need to create each FileLog with ServerName.

I think cannot use two Opentextfile before close one.

Can we help me?

This is code I'm using for test:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("Servers.txt")
Do Until objFile.AtEndOfStream
    strComputer = objFile.ReadLine
Set objFile2 = objFSO.CreateTextFile(strComputer & ".txt",True)
set objHtml=objFSO.OpenTextFile(objFile2,8,true)
objHtml.WriteLine Now() & VbTab & RegResultQuery
objHtml.Close
Loop
  • Read [OpenTextFile Method](https://msdn.microsoft.com/en-us/library/314cz14s(v=vs.84).aspx) reference: the first parameter should be a _String expression_ that identifies the file to open, but `objFile2` is a _TextStream_ **object** previously defined using the `CreateTextFile` method. Please read and follow How to create a [mcve]! – JosefZ Sep 14 '15 at 20:41

1 Answers1

0

You can call OpenTextFile twice, but you can't open the same file twice without closing it first. From what I see you don't need to open the file twice, though. CreateTextFile already returns a handle to the file, so you can simply use objFile2 throughout the loops.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328