Exclusive File access to logfile with VBScript and FileSystemObject

Rahim picture Rahim · Oct 30, 2008 · Viewed 7.8k times · Source

I have a VBS script that currently writes to a logfile. This script can be kicked off my multiple simultaneous processes so now I'm worried about concurrency.

I'm currently using FileSystemObject to open and write to this file. Does FSO support exclusive file access?

Answer

Jason Down picture Jason Down · Oct 30, 2008

Yes, FileSystemObject does support exclusive file access. If another process has a lock on the file when you call OpenTextFile, you will get an error (a permission denied error). You should be able to trap the error and handle it appropriately (check that Err.Number <> 0 after the call to OpenTextFile is one way you could do that).