Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Error 33 Locking Violation lockfile resource lock
I have an ini file on the network that I want multiple users to be able to read/write to. What do I need to do to prevent share violations and/or corruption of data when multiple users try to use that file at the same time. I am using iniwritepvt and inireadpvt functions and am not sure how they handle file open/closes. Thanks!
It's also a good idea to mark your WinBatch EXEs and DLLs as Read-only, so that they don't get totalled.
For multiple users on the network accessing the same ini file with ini operations requires a lot of care.
Netdir="N:\stuff\" inifile=strcat(netdir,"yourini.ini") lockfile=strcat(netdir,"lock.txt") lock=0 while lock ==0 Errormode(@off) lock=FileOpen(lockfile,"WRITE") Errormode(@cancel) if lock!=0 then break TimeDelay(0.5) endwhile iniWritePvt("section","key",123,inifile) iniwritepvt("","","",inifile) FileClose(lock)
;Lock Code example. ;Define lock lockfile="X:\someplac\lockfile.lck" ;Lock ini file ErrorMode(@off) for x=1 to 10 fh=FileOpen(lockfile,"WRITE") if fh==0 TimeDelay(2) else break endif next ErrorMode(@CANCEL) ;Don't even consider removing this line if fh==0 Message("Ooopsie","Could not obtain application lock") exit endif ; lock is secured ;Do your stuff here z=IniReadPvt(... z=z+1 IniWritePvt(... IniWritePvt("","","",inifilename);force ini data to disk. ;Release Lock FileClose(fh)
FileOpen( filename, "WRITE" )does this create a new file, and if the file exists, overwrite it? I tried to open the file with APPEND. This wouldn't zero the file, but now I was not able to do the IniReadPvt() because the file was locked???
The IniReadPvt and IniWritePvt functions work fine if I don't open/lock the file, but they don't work if the file is opened first.
Here's my code:
;Lock ini file ErrorMode(@off) fh=FileOpen(lockfile,"WRITE") ErrorMode(@CANCEL) if fh==0 Message("Ooopsie","Could not lock") exit endif ; lock is secured ;Do your stuff here z=IniReadPvt(... z=z+1 IniWritePvt(... ;Release Lock FileClose(fh)
And before you clear the lock (with the release lock of FileClose(fh)) do a:
IniWritePvt("","","",youinifile) TimeDelay(3)So here's the general concept:
If WinBatch is the ONLY program that references the file...
IniWritePvt("","","",inifilename)to force a dump of the local machine cache of the ini file to disk.
Article ID: W13169
Filename: Make a resource LOCK.txt
File Created: 2003:01:29:16:35:32
Last Updated: 2003:01:29:16:35:32