I launch several vbs, they write the information to one common log-file.
That I should do to prevent possible conflicts?
Thanks.

Re: Common log-file by Torgeir

Torgeir
Mon Jul 25 05:48:17 CDT 2005

Uka Miuinnen wrote:

> I launch several vbs, they write the information to one common
> log-file. That I should do to prevent possible conflicts?
> Thanks.
Hi,

If the file is locked, your scripts can go into a loop and wait for it
to be free, like this:

'--------------------8<----------------------

Const ForAppending = 8

' log file
sLogFile = "C:\logging.txt"

Set oFSO = CreateObject("Scripting.FileSystemObject")
bFileLockedExternal = True ' init value

On Error Resume Next
Do
' open for appending
Set fLogFile = oFSO.OpenTextFile(sLogFile, ForAppending, True)
If Err.Number = 70 Then
'Permission denied error, another process have the file open
' Waiting 1/2 a second before trying again
WScript.Sleep 500
Elseif Err.Number <> 0 then
WScript.Echo "Quitting, unexpected Error #: " & Err.Number
WScript.Quit
Else
On Error GoTo 0
' File is now opened by this script
bFileLockedExternal = False
End If
Err.Clear
Loop While bFileLockedExternal
On Error GoTo 0

' do the job here, the file will now be locked by this script and
' nobody else will be able to update it until the fLogFile.Close
' instruction below is run...

' writing something to the log file
fLogFile.WriteLine "Something"

' close the file so others can be able to continue
fLogFile.Close

'--------------------8<----------------------



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx