InterviewSolution
| 1. |
Solve : Batch Script searching an exe file and execute it.? |
|
Answer» Hi Guys, SET filename=msaccess.exe I would use the snippet you have, as such: Code: [Select]@ECHO OFF :Start REM Change name to whatever the db name is, not access itself. SET filename=NameOfDB.accdb FOR /R C:\ %%a IN (\) DO ( IF EXIST "%%a\%filename%" ( SET filedir = %%a SET fullpath=%%a%filename% GOTO break ) ) :break REM This says change to the file directory. If directory errors twice, then an error message is displayed. cd %filedir% || cd /d %filedir% || ECHO There has been an error locating - %fullpath% - Path may contain spaces or symbols that cause this error. REM If the file exists, calling it with a start command will launch the associated program. start %filename% REM ----------------------------------------------------------------- REM This snippet added for double checking and closing. REM ----------------------------------------------------------------- REM change "msaccess.exe" for use with another program name (if it is ANYTHING else). tasklist /nh /fi "imagename eq msaccess.exe" | find /i "msaccess.exe" >nul && ( exit ) || ( Echo The script has errored, and MS Access is not running. echo Check script for errors and/or check MS Access version for calling compatibility. echo PRESS any key to attempt the search again. Close the window to exit. goto Start ) ECHO Ambiguous error: CHECK SCRIPT FOR ERRORS. pause>nul exit I tested this, and I know that it isn't working atm... but I think it'll set you in the right direction. I'll try to update this with something working if I can... but I'm pretty busy right now. |
|