1

When using a batch file, is there a command I can use to check if Access 2010 Runtime is currently installed and if is not, then invoke it's installation?

This will be used on both Windows 7 and Windows XP.

Edit: looking for a way to check for the installation of the program without knowing where the files are put when Access Runtime is installed.

0

4 Answers 4

2

You can read the information from the registry:

reg.exe QUERY HKLM\SOFTWARE\Classes\Access.Application.14\shell\Open\command /ve

This commands reads the MSAccess.EXE path from the registry. You just need to save it into a variable and then remove the garbage around it. That can be done using "for" command.

2

As an alternative to the registry, if you want to check if it's installed, wmic can do that. The commands for checking installed programs typically take a bit of time to run, however.

wmic product where "name like 'WhateverAccessRuntimeIsCalled'" get version

To check what it's actually called (you need exact name) and correct version, install it on your own computer. Then, on your own computer:

wmic product get name,version>programlist.txt && notepad.exe programlist.txt && del programlist.txt

You can then, in the batch file, run the query command:

setlocal EnableDelayedExpansion

for /f "skip=1 tokens=1 usebackq delims=." %%a in (`wmic product where "name like 'WhateverAccessRuntimeIsCalled'" get version`) do (
    if /i "!_versionstring!" LSS "%%a" (
        set _versionstring=%%a
    )
)

if /i "%_versionstring%" LSS "WhateverTheMajorVersionNumberShouldBe" (
    echo It's not installed
) else (
    echo It is installed
)

Office 2010 has a major version number (the first number, separated by dots) of 14. Of course, if the program name has "2010" in it, there isn't really a need to check the version number. If the program doesn't exist, %_versionstring% will be empty.

Checking the registry is definitely faster, but I would argue this is the 'correct' way to check if a MSI based program is installed.

3
  • wmic is a nice idea. But AFAIK wmic is not available by default on Windows XP.
    – Robert
    Apr 26, 2012 at 15:17
  • @Robert It isn't? Ok, scrap this idea then. Checking the registry, perhaps the uninstall keys, would be the way to go then.
    – Bob
    Apr 26, 2012 at 22:23
  • I checked the availability of WMIC on XP and I have to say that I was partly wrong. WMIC came with SP2 but it is only installed if it is an XP Professional version. Therefore WMIC is only unavailable on XP Home.
    – Robert
    Apr 27, 2012 at 8:08
1

I'm surprised you didn't find that command
IF NOT ACCESS2000RunTimeInstallation RUN ACCESS2000RuntimeInstallation
;-)

But anyhow,

Here is the principle.

I have a file called a.a and a directory called c:\windows. I don't have a file called a.b and I don't have a directory called c:\windows1

One can say

if exist a.a c:\program\program.exe

In the examples below, you can replace "echo here", with the path of a program

Now find out what files the access 2000 installation thing puts in the hard drive and pick a unique one, or a directory it makes, and use that for your IF statement.

C:\>if exist a.a echo here
here

C:\>if exist a.b echo here

C:\>if exist c:\windows\nul echo here
here

C:\>if exist c:\windows1\nul echo here

C:\>

Update-

You can also check the registry

As an example, whatever the program, one place you might see the thing is in Add/Remove programs. Here is the place in the registry where that is stored. You can run that command and scroll through that just to get an idea of the command

C:\>reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Unins
tall | more

One program listed is Windows Media Player, which you'd have too

C:\>reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Unin
stall\Windows Media Player"

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Windows M
edia Player
    DisplayName REG_SZ  Windows Media Player 10
    UninstallString     REG_SZ  "C:\Program Files\Windows Media Player\Setup_wm.
exe" /Uninstall
    DisplayIcon REG_SZ  C:\Program Files\Windows Media Player\wmplayer.exe
    ParentKeyName       REG_SZ  OperatingSystem
    ParentDisplayName   REG_SZ  Windows Updates

C:\>

That "successful" reg query command sets ERRORLEVEL to 0, meaning no error.

C:\>echo %errorlevel%
0

If the key didn't exist e.g. I look for Windows Media Playerr (notice the extra r)

C:\>reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Unin
stall\Windows Media Playerr"

Error:  The system was unable to find the specified registry key or value

C:\>echo %errorlevel%
1

C:\>

When %errorlevel% is >=1 then it means error.

So you can test IF %errorlevel%==0 You can test IF NOT %errorlevel%==0 You can use an ELSE

The other syntax for testing ERRORLEVEL, don't do if errorlevel 0 (silly) 'cos that asks the value is >=0. You say IF ERRORLEVEL 1 (i.e. if the value is >=1) , or IF NOT ERRORLEVEL 1 (i.e. if the value is not >=1 i.e. if the value is 0 or less - and I doubt it could ever be less). Or you use the %errorlevel%.

2
  • Thank you for this input. I understand how the IF EXIST command works and use it to check for some other files. What if I don't know where the installer puts things or what files are unique to Access 2010 Runtime?
    – CharlieRB
    Apr 25, 2012 at 12:55
  • 1
    you can check the registry too, see my update. If you don't know what files or registry entries it makes, then you could run an uninstaller, monitor the installation or before and after the installation, and see what files or registry entries it puts on there, and check for a few. Then you can be sure it's unique! Or, you could see what registry entry it makes in Add/Remove programs. That's probably unique.
    – barlop
    Apr 25, 2012 at 15:00
1

To simply check whether Access Runtime 2010 is installed or not i use this line

REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Office14.AccessRT" /v DisplayName

and as mentioned before you can catch the %errorlevel% for further instructions

For example a logon script i wrote :

@echo off

:: test whether your PC has Access or Access Runtime only if you are in the list 

find/i "%COMPUTERNAME%" \\someserver\folder\list.txt >nul
 if %errorlevel%==1 goto end

:: set some variables false because batch has no logical OR
set accessTest=False
set accessExeTest=False

if exist "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" ( 
  set accessExeTest=x86 )

if exist "C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" (
  set accessExeTest=x86_64 )

if exist "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Access 2010.lnk" (
    set accessTest=True
  )

REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Office14.AccessRT" /v DisplayName
if %errorlevel%==0 (
    set accessTest=True
  )

:: execute only if a start menu entry or the registry key is found
if %accessTest%==True (

  :: import registry key to flag the DB as trusted
  reg import \\someserver\public\ACCESS\allowAccess.reg

  :: choose from where to start access
  if %accessExeTest%==x86 (
    start "" "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" \\someserver\public\ACCESS\someDB.accdb /runtime  /nostartup
  ) else if %accessExeTest%==x86_64 (
    start "" "C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" \\someserver\public\ACCESS\someDB.accdb /runtime  /nostartup
  )
:: log the ones without any form of MS Access
else (
  echo %COMPUTERNAME%>>\\someserver\HWINFO\access.log )
)

:end

you could also check for the location of the MSACCESS.EXE with

REG QUERY HKLM\SOFTWARE\Classes\Access.Application.14\shell\Open\command /ve

and search for the relevant information. but i noticed that that is not always reliable. Sometimes the *.exe is there but it doesnt work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .