@echo off
setlocal
set Directory=%~1
set FileName=%~2
set FileBaseName=%~n2
if exist "%Directory%\%FileBaseName%.laccdb" (
msg.exe %username% "%~nx0: The application is already open or closed improperly. If the application is not running, contact Steve"
exit /b 1
)
:Continue
echo Starting '%Directory%\%FileName%' ...
REM ...
if not exist "%~1\%~n2.laccdb" (your logic is reversed; if the lock file exists, the script needs to leave.
@oBdA
is msg.exe a Windows file?
Bill, is that the file you were talking about in your original post?
msg.exe %username% "Hello World"
Bill, is that the file you were talking about in your original post?
@echo off
setlocal
if exist "%~1\%~n2.laccdb" (
echo MsgBox "The application is already open or closed improperly." ^& vbCrLf ^& vbCrLf ^& "If the application is not running, contact Steve", vbOkOnly, "Warning - Already Running" >"%TEMP%\%~n0.vbs"
wscript.exe "%TEMP%\%~n0.vbs"
del "%TEMP%\%~n0.vbs"
exit /b
)
Bill,
I like the VB script version, here is what I'm using now for my test, and it's not working properly. When I currently run the first batch file I get a screen flicker when a command box opens and then closes, but no other messages:
Routine which calls the 2nd bat:
@echo off
:: Launches a Bat file which checks to see if a file (2nd argument with .laccdb) exists in the folder (1st argument)
CALL E:\Developing Solutions\TestFolder\FileExists.bat "C:\Users\Admin\AppData\Roaming\Microsoft\Addins\" "Test.accdb"
And the FileExist.bat:
@echo off
setlocal
:: Accepts two parameters, a folder name and a filename
:: Checks to see whether the filename with a ".laccdb" extension exists and displays message
::if exist "%~1\%~n2.laccdb" (
echo MsgBox "The application is already open or closed improperly." ^& vbCrLf ^& vbCrLf ^& "If the application is not running, contact your system administator", vbOkOnly, "Warning - Already Running" >"%TEMP%\%~n0.vbs"
wscript.exe "%TEMP%\%~n0.vbs"
del "%TEMP%\%~n0.vbs"
exit /b
)
echo MsgBox "The application was not running", vbOkOnly, "Continue" >"%TEMP%\%~n0.vbs"
wscript.exe "%TEMP%\%~n0.vbs"
del "%TEMP%\%~n0.vbs"
In the first bat, if this .bat is in the same folder as the 2nd, do I need the full path name or can I simply use:
Call FileExists.Bat "arg1" "arg2"
Thanks, to both of you, that really helped, it has been so long since I've used batch files!
Here's the basic idea, although a popup from BAT is a little tricky, how pretty do you want that to be, and are you opposed to using a very small freeware utility EXE (standalone EVE, no install) that I often use?
First, here's the called BAT file (EE29170747.BAT in my test):
Open in new window
And here's an example of calling it:
Open in new window