I'm trying to log certain information from my network of Windows machines; I've set them to periodically collect this info, then I want it in a single CSV file on a network drive. I'm using a VBS to collect this data, using OpenTextFile in append mode for writing. Will this allow multiple computers to simultaneously append a line to this file? Or is there another way to do this (apart from storing a separate file for each device).
I don't care about the order (I collect a timestamp from each device).
Best Answer
Windows has the ability to share concurrent access to files through mechanisms such as byte-range locks, whereby a process locks only a certain region of a file, etc. But applications have to be written appropriately to take advantage of this. It is entirely possible to code your application in such a way that you lock the entire file, and not just a region of it. You can even lock a file so that another process cannot even read from it.
However, you complicate things when you talk about accessing a file on a network file share. Now we're accessing files over the SMB network protocol.
SMB uses oplocks (opportunistic locks) and leases to manage concurrent access to files. The types of oplocks and leases are as follows:
Oplocks
Leases
Windows Internals 6th ed., Mark Russinovich, et al.
None of these modes are going to give you the shared write access you seek.
Change your strategy. Like MDMarra said, the Windows event log is a better choice. Another idea would be to have all the clients write to their own files in the file share, then have a server process collect all the files and aggregate them. You mention in your question that you're writing code, so you're in a position to change how this application works. I would suggest going to StackOverflow and asking them about the best way to approach shared write access to a single file over the network.