Find path to outlook.exe

J

Jack Leach

oops... IsMissing only works on Variant Optionals... updated version below

sorry about that...



'====== CODE START

Option Compare Database
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
'Note that if you declare the lpData parameter as String,
'you must pass it ByVal.


Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long)
As Long

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

Public Enum eOfficeApp
eOfficeAppaccess = 0
eOfficeAppExcel = 1
eOfficeAppoutlook = 2
eOfficeAppPowerpoint = 3
eOfficeAppword = 4
eOfficeAppFrontPage = 5
End Enum


Public Function fGetOfficeEXE(lApp As eOfficeApp, _
Optional vVer As Variant) As String
Dim hKey As Long
Dim RetVal As Long
Dim sProgId As String
Dim sCLSID As String
Dim sPath As String

Select Case lApp
Case 0: sProgId = "Access"
Case 1: sProgId = "Excel"
Case 2: sProgId = "Outlook"
Case 3: sProgId = "Powerpoint"
Case 4: sProgId = "Word"
Case 5: sProgId = "FrontPage"
End Select

sProgId = sProgId & ".Application"

If Not IsMissing(vVer) Then sProgId = sProgId & "." & Trim(CStr(vVer))

'First, get the clsid from the progid
'from the registry key:
'HKEY_LOCAL_MACHINE\Software\Classes\<PROGID>\CLSID
RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Classes\" & _
sProgId & "\CLSID", 0&, KEY_ALL_ACCESS, hKey)
If RetVal = 0 Then
Dim n As Long
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, "", n)
sCLSID = Space(n)
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, sCLSID, n)
sCLSID = Left(sCLSID, n - 1) 'drop null-terminator
RegCloseKey hKey
End If

'Now that we have the CLSID, locate the server path at
'HKEY_LOCAL_MACHINE\Software\Classes\CLSID\
' {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx}\LocalServer32

RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
"Software\Classes\CLSID\" & sCLSID & "\LocalServer32", 0&, _
KEY_ALL_ACCESS, hKey)
If RetVal = 0 Then
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, "", n)
sPath = Space(n)

RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, sPath, n)
sPath = Left(sPath, n - 1)
'MsgBox sPath
RegCloseKey hKey
End If

fGetOfficeEXE = sPath
End Function

'====== CODE END

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
H

Hugh self taught

Morning Jack,

Thanks for the zips, works fine. Don't know what was faulty on my copy /
paste copy but I can make progress now. Just have to pass that to my form to
test the next part.

P.S.
vVer variable not defined in your latest post
 
H

Hugh self taught

Morning Jack,

Thanks for the zips, works fine. Don't know what was faulty on my copy /
paste copy but I can make progress now. Just have to pass that to my form to
test the next part.

P.S.
vVer variable not defined in your latest post
 
J

Jack Leach

P.S.
vVer variable not defined in your latest post

vVer is defined as an optional argument in the last post. The zip I sent
you didn't have it (it was an afterthought, really).


Declared as a Variant, otherwise the IsMissing() doesn't work.


If the user enters a value for vVer in the caller, it gets converted to a
string and added.


I've noticed that the API returns a ZLS (or Null, I didn't test to see) if
you enter arguments for programs that don't exist. For instance,
"FrontPage.Application" returns ZLS on my computer as I don't have it
installed, or if I use "Excel.Application.12" I get it also, being that
version 11 is installed on mine.

Maybe there was a minor type in this part when you were trying it.

Glad to hear you got it working.

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

P.S.
vVer variable not defined in your latest post

vVer is defined as an optional argument in the last post. The zip I sent
you didn't have it (it was an afterthought, really).


Declared as a Variant, otherwise the IsMissing() doesn't work.


If the user enters a value for vVer in the caller, it gets converted to a
string and added.


I've noticed that the API returns a ZLS (or Null, I didn't test to see) if
you enter arguments for programs that don't exist. For instance,
"FrontPage.Application" returns ZLS on my computer as I don't have it
installed, or if I use "Excel.Application.12" I get it also, being that
version 11 is installed on mine.

Maybe there was a minor type in this part when you were trying it.

Glad to hear you got it working.

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top