This script will work except when both pc's run it at about the same time. The phrase "about the same time" means that the second PC does not run its script during the period when first one is performing its copy and before it has a chance to set .lock.
You can reduce the fatal time by defining your own lock file on one of the PC's. Have your script read the lock file and, if it is unlocked, set the lock, then copy the catalog and start LR. The second PC would run a similar script, but would refer to the same lock file as the other. Doing this will reduce the danger time to the time needed to read, test and write the lock.
I spent a number of years looking for just this kind of logic in much more stringent environments and a correct solution actually takes some assistance from some special piece of hardware that allows multiple machines to ask the question "are you currently locked" and answering either "no, I wasn't but I am now" or "yes, sorry, try again later". This hardware also needs to take a request "please unlock" from the machine holding the lock.
Alan
Yes, there is the possibility of a conflict if 2 people run the batch file at the same time. This is especially likely to happen if the network isn't too fast and the catalogs are large as it may take a significant time to copy the catalogs before launching Lightroom (which will also take some time). Here is an improvement on the script that gets over this problem:
copy /y NUL \\thisPC\Lightroom\Lightroom Catalogs\temp.lock
net use \\otherPC "password" /user:UserName /persistent:no
if exist "\\otherPC\Lightroom\Lightroom Catalogs\*.lock" (
echo Lightroom running in otherPC
pause
del \\thisPC\Lightroom\Lightroom Catalogs\temp.lock
exit
)
xcopy "\\otherPC\Lightroom\Lightroom Catalogs\*.lrcat" "\\thisPC\Lightroom\Lightroom Catalogs\" /Y /D
start "" "C:\Program Files\Adobe\Adobe Lightroom\lightroom.exe"
del \\thisPC\Lightroom\Lightroom Catalogs\temp.lock
exit
But of course there is still the very slight chance that the users will hit run the script at exactly the same time. Getting over this isn't easy as you say, so one solution is to give the other guy a shout before hitting the button
The worst case scenario though is that the edits (not saved to xmp) made by the first user to exit LR would be lost. So it would be very advisable to always have changes written to xmp.
Another possible improvement would be to pause for a few seconds after launching LR, then check again that there is no lockfile and if there is to scream blue murder, something like this:
copy /y NUL \\thisPC\Lightroom\Lightroom Catalogs\temp.lock
net use \\otherPC "password" /user:UserName /persistent:no
if exist "\\otherPC\Lightroom\Lightroom Catalogs\*.lock" (
echo Lightroom running in otherPC
pause
del \\thisPC\Lightroom\Lightroom Catalogs\temp.lock
exit
)
xcopy "\\otherPC\Lightroom\Lightroom Catalogs\*.lrcat" "\\thisPC\Lightroom\Lightroom Catalogs\" /Y /D
start "" "C:\Program Files\Adobe\Adobe Lightroom\lightroom.exe"
timeout /t 30 /nobreak
if exist "\\otherPC\Lightroom\Lightroom Catalogs\*.lock" (
mshta "javascript:alert('OTHER USER HAS STARTED LIGHTROOM ... STOP!!! NOW!!!!');"
)
del \\thisPC\Lightroom\Lightroom Catalogs\temp.lock
exit
Robert