Is there a batch command to check for Access 2010 Runtime installation?

1

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.

CharlieRB

Posted 2012-04-24T15:39:34.920

Reputation: 21 303

Answers

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.

Robert

Posted 2012-04-24T15:39:34.920

Reputation: 4 857

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.

Bob

Posted 2012-04-24T15:39:34.920

Reputation: 51 526

wmic is a nice idea. But AFAIK wmic is not available by default on Windows XP. – Robert – 2012-04-26T15:17:25.417

@Robert It isn't? Ok, scrap this idea then. Checking the registry, perhaps the uninstall keys, would be the way to go then. – Bob – 2012-04-26T22:23:17.327

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 – 2012-04-27T08:08:09.573

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.

django Kunzmann

Posted 2012-04-24T15:39:34.920

Reputation: 11

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%.

barlop

Posted 2012-04-24T15:39:34.920

Reputation: 18 677

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 – 2012-04-25T12:55:08.377

1you 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 – 2012-04-25T15:00:48.390