Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine whether an applications is installed 2

Status
Not open for further replies.

emergencyplan

Technical User
Aug 19, 2003
34
GB
Hello,

I have a program that copies files from a CD to the users machine and creates a shortcut to an Access database copied from the CD.

How can I determine, firstly that Access is installed on the machine and secondly, what the path is for the Access.exe? (e.g. it could reside on the C:\ or D:\ drives depending on the users machine)

Thanks,
 
I think the path is by default : "\Program Files\Microsoft Office\Office\MSACCESS.EXE"

You could scan the available drives on the PC to see if you can find it.
 
thread222-683524 should contain all you need to know to find out where Access is; I have a slightly shorter version than the code presented there by vb5prgrmr, but it is pretty similar, so probably not worth posting here.
 
If IE 5 or higher is present, can use the AssocQueryString API function:
Code:
Declare Function AssocQueryString Lib "shlwapi.dll" Alias "AssocQueryStringA" _
(Byval flags As Long, Byval pstr As Long, Byval pszAssoc As String, Byval pszExtra As String, _
Byval pszOut As String, Byval pcchOut As Long) As Long

'dont truncate the return string
Const ASSOCF_NOTRUNCATE = &H20
'return the the executable part of command string
Const ASSOCSTR_EXECUTABLE = 2
'actually gets info about rundlls target if applicable
Const ASSOCF_REMAPRUNDLL = &H80
Const S_OK = 0
Const E_POINTER = &H80004003

Function fGetAppPath(Byval strExt As String) As String

 '--- Returns the path to an executable or an empty string if an error occurs

 '--- Input
 ' strExt is the three character file extension associated with the executable

 Dim lngRtn As Long
 Dim lngBuffLen As Long
 Dim lngFlags As Long
Dim strAppPath As String
 
 'Check strExt isn't empty
 If strExt = vbNullString Then
  Exit Function
 End If

 'Set the flags
 lngFlags =  ASSOCF_NOTRUNCATE Or ASSOCF_REMAPRUNDLL
 'Null terminate the file extension
 strExt = "." & strExt & vbNullChar

 'Size the buffer for the return value
 strAppPath = Space(255)
 lngBuffLen = 255

 'Get the exe path
 lngRtn = AssocQueryString(lngFlags, ASSOCSTR_EXECUTABLE, _
 strExt, vbNullString, strAppPath, lngBuffLen)
 'Check the result
 Select Case lngRtn
 Case S_OK
  'Success, do nothing
 Case E_POINTER
  'Buffer was too small - resize it and try again
  strAppPath = Space(lngBuffLen)
  lngRtn = AssocQueryString(lngFlags, ASSOCSTR_EXECUTABLE, _
  strExt, vbNullString, strAppPath, lngBuffLen)
 Case Else
  'An error occurred - exit
  Exit Function
 End Select

 'Strip the terminating null char and remaining spaces
 fGetAppPath = Left$(strAppPath, Instr(1, strAppPath, vbNullChar) -1)

End Function
Call the function with "mdb" as the file extension to get the path to the Access executable.
Another way is to read the registry; paths of all Office apps are stored there.


Paul Bent
Northwind IT Systems
 
Hello again,

Another related question....how can I determine the version of the application installed? I have found how to determine the operating system but not the version of a program (e.g. Access 2000 or Access 97).

Thanks again,

Laurence

 
Once you have obtained the file path to the MS Access executable, you can pass this filename to the following function to obtain the version of the office it belongs to.
___
[tt]
Option Explicit
Private Declare Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
Private Declare Function VerQueryValue Lib "version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lpBuffer As Long, puLen As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type VS_FIXEDFILEINFO
dwSignature As Long
dwStrucVersion As Long
dwFileVersionMS As Long
dwFileVersionLS As Long
dwProductVersionMS As Long
dwProductVersionLS As Long
dwFileFlagsMask As Long
dwFileFlags As Long
dwFileOS As Long
dwFileType As Long
dwFileSubtype As Long
dwFileDateMS As Long
dwFileDateLS As Long
End Type

Private Sub Form_Load()
Dim FileName As String
'We assume that we have obtained this file path programatically.
FileName = "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
MsgBox GetOfficeAppVersion(FileName)
End Sub

Function GetOfficeAppVersion(strOfficeApp As String) As String
Dim B() As Byte, vsffi As VS_FIXEDFILEINFO
Dim lngVerSize As Long, lngDataPointer As Long, lngMajorVersion As Long

'Get the size of the version info resource.
lngVerSize = GetFileVersionInfoSize(strOfficeApp, ByVal 0)
If lngVerSize = 0 Then Exit Function

'Create buffer for the version info resource.
ReDim B(0 To lngVerSize - 1)

'Get the version info data.
GetFileVersionInfo strOfficeApp, 0, lngVerSize, B(0)

'Query the pointer of VS_FIXEDFILEINFO
'structure from the version info data.
VerQueryValue B(0), "\", lngDataPointer, ByVal 0

'Fill the VS_FIXEDFILEINFO structure from the pointer.
CopyMemory vsffi, ByVal lngDataPointer, Len(vsffi)

'Obtain the major version of the application
'(Major version resides in the hi-word of the
'dwFileVersionMS member of this structure).
lngMajorVersion = vsffi.dwFileVersionMS \ &H10000

'Finally, determine the office app version.
Select Case lngMajorVersion
Case 8: GetOfficeAppVersion = "97"
Case 9: GetOfficeAppVersion = "2000"
Case 10: GetOfficeAppVersion = "XP"
Case 11: GetOfficeAppVersion = "2003"
Case Else: GetOfficeAppVersion = "Unknown"
End Select
End Function[/tt]
___

See also thread222-743816 which also gives some other methods to obtain the MS Office version using VBScript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top