1.

Solve : Batch Script searching an exe file and execute it.?

Answer»

Hi Guys,

I'm a new guy here, and looking forward for your assistance.

I developed an ms access database and WANT the USER to invoke it thru batch script, my problem is each users INSTALLED their ms access software in different location (not consistent), my intension is to locate that ms access exe and execute it. I have my initial script but the output giving me "\\" before the exe file name (i.e. C:\PATH\\MSACCESS.EXE).

Here's my code: This script is giving the result on the first occurance only (first find)

Code: [Select]@ECHO OFF

SET filename=msaccess.exe

FOR /R C:\ %%a IN (\) DO (
IF EXIST "%%a\%filename%" (

SET fullpath=%%a%filename%
GOTO break
)
)
:break

ECHO %fullpath%

pause>nul
Any Help will be appreciated.

Thanks Guys.A while back when dealing with Access97 and 2000, I just used this instruction which worked:

msaccess.exe "\\UNC Path to \database.mdb"


You place your shared database location into the UNC path. This way it doesnt matter where MS Access is installed, Windows knows where MS Access is and invoking this command with a UNC Path should work for you. The Batch File could be a single line, however you can do away with batch and just mail a shortcut that invokes MSACCESS.EXE "\\Database_Path_Location\Name.mdb"

As long as everyone is running same version of Access, installation location not important, you are all set, however if this database is for say 2003 and you have users with other versions you can run into version mismatches and run into issues which you are probably already aware of.One of the first things, is that you are calling msaccess.exe, not a specified db file.

Quote

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.


Discussion

No Comment Found