Can I prevent more than one user from running a batch file at the same time
1 answer
A simple solution to check if the batch file is running is to use the file system.
The batch file can check if the file exists and disallow execution in this case, otherwise it creates the file, runs commands, and finally deletes the file.
@echo off
if exist "C:\Temp\BatchLock.txt" goto BatchRunning
echo Batch file is running by %username%.>C:\Temp\BatchLock.txt
rem All other commands of the batch file
del C:\Temp\BatchLock.txt
goto :EOF
:BatchRunning
type C:\Temp\BatchLock.txt
echo/
echo Please run the batch later again.
echo/
echo Press any key to exit ...
pause >nul
Certainly C:\Temp
not a good place to store a lock text file. This should be a directory that is identical for all users, a directory on the server with write permissions for all users.
+2
source to share