Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for lockprog.bat

(view source code of lockprog.bat as plain text)

  1. @ECHO OFF
  2. :: Check if program is locked, and by whom
  3. IF EXIST LOCKED.BAT CALL LOCKED.BAT
  4. :: Unlock if it was you yorself who locked it
  5. IF "%LOCKEDBY%"=="%1" DEL LOCKED.BAT
  6. :: Check again if program is locked, and by whom
  7. IF EXIST LOCKED.BAT GOTO Locked
  8. :: Lock it if it isn't locked by someone else
  9. ECHO SET LOCKEDBY=%1>LOCKED.BAT
  10. :: Start the program
  11. :: (the first command line parameter, %1,
  12. :: was used for this locking batch file)
  13. MYPROGRAM.EXE %2 %3 %4 %5 %6 %7 %8 %9
  14. :: Free the program
  15. SET LOCKEDBY=
  16. DEL LOCKED.BAT
  17. :: And quit
  18. GOTO End
  19.  
  20. :Locked
  21. CALL LOCKED.BAT
  22. ECHO.
  23. IF "%LOCKEDBY%"=="" GOTO Locked2
  24. ECHO %LOCKEDBY% uses MYPROGRAM right now.
  25. ECHO %LOCKEDBY% can free MYPROGRAM again by closing it normally.
  26. GOTO Errors
  27.  
  28. :Locked2
  29. ECHO Someone else has locked MYPROGRAM.
  30. ECHO Contact your helpdesk or administrator.
  31.  
  32. :Errors
  33. ECHO.
  34. PAUSE
  35.  
  36. :End
  37.  

page last uploaded: 2017-04-06, 13:33