Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

Detect Version of MSAccess

I am using a VB prog to open an access database.  It will open a A2k database if A2k is installed, otherwise it will open A97 version.

I simply need to determine if A2k is installed on the machine, without opening Access to do it.

Thanks,

JS
0
jdlsmith
Asked:
jdlsmith
  • 5
  • 3
1 Solution
 
jrspanoCommented:
why not find the file msaccess.exe and then get the version of it 2000 is 9.0.0.buildversion

i think 97 is version 8.0.0
0
 
jdlsmithAuthor Commented:
How do you get the version?
0
 
jdlsmithAuthor Commented:
How do you get the version?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jrspanoCommented:
here is code from freevbcode.com to get the paths to office products

Option Explicit

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
   "RegOpenKeyExA" (ByVal hKey As Long, _
   ByVal lpSubKey As String, ByVal ulOptions As Long, _
   ByVal samDesired As Long, phkResult As Long) _
   As Long

Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
   Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal _
   lpValueName As String, ByVal lpReserved As Long, _
   lpType As Long, ByVal lpData As String, lpcbData As Long) _
   As Long
                                                                                                 
Private Declare Function RegCloseKey Lib "advapi32.dll" _
   (ByVal hKey As Long) As Long

Private Const REG_SZ As Long = 1
Private Const KEY_ALL_ACCESS = &H3F
Private Const HKEY_LOCAL_MACHINE = &H80000002

Code:


'*****************************************************
'These functions return the path to the specified office
'application or a 0-length string if the application does not
'exist on the machine.  This is one good way to check whether a
'specific office application is present before trying to run
'automation code for that application
'*****************************************************
Public Function GetWordPath() As String
    GetWordPath = GetOfficeAppPath("Word.Application")
End Function

Public Function GetExcelPath() As String
    GetExcelPath = GetOfficeAppPath("Excel.Application")
End Function

Public Function GetAccessPath() As String
    GetAccessPath = GetOfficeAppPath("Access.Application")
End Function

Public Function GetOutlookPath() As String
    GetOutlookPath = GetOfficeAppPath("Outlook.Application")
End Function

Public Function GetPowerPointPath() As String
    GetPowerPointPath = _
       GetOfficeAppPath("PowerPoint.Application")
End Function

Public Function GetFrontPagePath() As String
    GetFrontPagePath = GetOfficeAppPath("FrontPage.Application")
End Function

Private Function GetOfficeAppPath(ByVal ProgID As String) _
   As String

Dim lKey As Long
Dim lRet As Long
Dim sClassID As String
Dim sAns As String
Dim lngBuffer As Long
Dim lPos As Long

   'GetClassID
   lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
          "Software\Classes\" & ProgID & "\CLSID", 0&, _
           KEY_ALL_ACCESS, lKey)
   If lRet = 0 Then
 
      lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, "", lngBuffer)
      sClassID = Space(lngBuffer)
      lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, sClassID, _
          lngBuffer)

      'drop null-terminator
      sClassID = Left(sClassID, lngBuffer - 1)
      RegCloseKey lKey
   End If
   
   
   'Get AppPath
    lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
        "Software\Classes\CLSID\" & sClassID & _
        "\LocalServer32", 0&, KEY_ALL_ACCESS, lKey)
 
  If lRet = 0 Then
      lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, "", lngBuffer)
      sAns = Space(lngBuffer)
      lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, sAns, _
        lngBuffer)
      sAns = Left(sAns, lngBuffer - 1)
     
      RegCloseKey lKey
   End If
   
   
    'Sometimes the registry will return a switch
       'beginning with "/" e.g., "/automation"
   
    lPos = InStr(sAns, "/")
        If lPos > 0 Then
            sAns = Trim(Left(sAns, lPos - 1))
        End If
   
    GetOfficeAppPath = sAns
   
End Function
0
 
jrspanoCommented:
once you have the path then use this


set a refference to ms scripting runtime

Dim f As New FileSystemObject
Dim s As String

s = f.GetFileVersion(path and filename)
this will give you the version
0
 
jrspanoCommented:
here is the example put together

make a project with 1 form and add a command button with name command1 cut and paste code below


Option Explicit
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
  "RegOpenKeyExA" (ByVal hKey As Long, _
  ByVal lpSubKey As String, ByVal ulOptions As Long, _
  ByVal samDesired As Long, phkResult As Long) _
  As Long

Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
  Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal _
  lpValueName As String, ByVal lpReserved As Long, _
  lpType As Long, ByVal lpData As String, lpcbData As Long) _
  As Long
                                                                                                 
Private Declare Function RegCloseKey Lib "advapi32.dll" _
  (ByVal hKey As Long) As Long

Private Const REG_SZ As Long = 1
Private Const KEY_ALL_ACCESS = &H3F
Private Const HKEY_LOCAL_MACHINE = &H80000002



'*****************************************************
'These functions return the path to the specified office
'application or a 0-length string if the application does not
'exist on the machine.  This is one good way to check whether a
'specific office application is present before trying to run
'automation code for that application
'*****************************************************
Public Function GetWordPath() As String
   GetWordPath = GetOfficeAppPath("Word.Application")
End Function

Public Function GetExcelPath() As String
   GetExcelPath = GetOfficeAppPath("Excel.Application")
End Function

Public Function GetAccessPath() As String
   GetAccessPath = GetOfficeAppPath("Access.Application")
End Function

Public Function GetOutlookPath() As String
   GetOutlookPath = GetOfficeAppPath("Outlook.Application")
End Function

Public Function GetPowerPointPath() As String
   GetPowerPointPath = _
      GetOfficeAppPath("PowerPoint.Application")
End Function

Public Function GetFrontPagePath() As String
   GetFrontPagePath = GetOfficeAppPath("FrontPage.Application")
End Function

Private Function GetOfficeAppPath(ByVal ProgID As String) _
  As String

Dim lKey As Long
Dim lRet As Long
Dim sClassID As String
Dim sAns As String
Dim lngBuffer As Long
Dim lPos As Long

  'GetClassID
  lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
         "Software\Classes\" & ProgID & "\CLSID", 0&, _
          KEY_ALL_ACCESS, lKey)
  If lRet = 0 Then

     lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, "", lngBuffer)
     sClassID = Space(lngBuffer)
     lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, sClassID, _
         lngBuffer)

     'drop null-terminator
     sClassID = Left(sClassID, lngBuffer - 1)
     RegCloseKey lKey
  End If
 
   
  'Get AppPath
   lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
       "Software\Classes\CLSID\" & sClassID & _
       "\LocalServer32", 0&, KEY_ALL_ACCESS, lKey)

 If lRet = 0 Then
     lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, "", lngBuffer)
     sAns = Space(lngBuffer)
     lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, sAns, _
       lngBuffer)
     sAns = Left(sAns, lngBuffer - 1)
     
     RegCloseKey lKey
  End If
   
   
   'Sometimes the registry will return a switch
      'beginning with "/" e.g., "/automation"
   
   lPos = InStr(sAns, "/")
       If lPos > 0 Then
           sAns = Trim(Left(sAns, lPos - 1))
       End If
   
   GetOfficeAppPath = sAns
   
End Function


Private Sub Command1_Click()

Dim s As String
Dim a As String
s = GetAccessPath

Dim f As New FileSystemObject

a = f.GetFileVersion(s)  'a has version here

if left$(a,1) = "9" then
  'access2000
endif


End Sub
0
 
jdlsmithAuthor Commented:
Perfect!  appreciate the other code too (i'll implement it later)

Thanks!

JS
0
 
jrspanoCommented:
glad i could help!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now