C
CDMAPoster
I have changed how I get the shell path for Acrobat Reader based on
code posted by John deKrafft. Does anyone see any problems with this
code running on various Windows OS's?
'--Begin Module Code
'Support functions and constants for reading a string from the
registry
'I have modified the code posted by John deKrafft slightly
'----
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String,
ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As
Long) As Long
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
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long)
As Long
Public Const SYNCHRONIZE As Long = &H100000
Public Const STANDARD_RIGHTS_ALL As Long = &H1F0000
Public Const KEY_QUERY_VALUE As Long = &H1
Public Const KEY_SET_VALUE As Long = &H2
Public Const KEY_CREATE_SUB_KEY As Long = &H4
Public Const KEY_ENUMERATE_SUB_KEYS As Long = &H8
Public Const KEY_NOTIFY As Long = &H10
Public Const KEY_CREATE_LINK As Long = &H20
Public Const KEY_ALL_ACCESS As Long = ((STANDARD_RIGHTS_ALL Or _
KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or _
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not
SYNCHRONIZE))
Public Const ERROR_SUCCESS As Long = 0
Public Const HKEY_LOCAL_MACHINE As Long = &H80000002
Public Const HKEY_CLASSES_ROOT As Long = &H80000000 'Added
Public Function GetRegistryString(lngKey As Long, strSubKey As String,
strValue As String) As String
Dim lngDataType As Long
Dim lngDataLength As Long
Dim strDataString As String
Dim lngResult As Long
Dim lngHandle As Long
Const StringLength = 150
strDataString = Space(StringLength)
lngDataType = 0
lngDataLength = CLng(StringLength)
lngResult = RegOpenKeyEx(lngKey, strSubKey, 0, KEY_ALL_ACCESS,
lngHandle)
If lngResult <> ERROR_SUCCESS Then
GetRegistryString = "Error"
Exit Function
End If
lngResult = RegQueryValueEx(lngHandle, strValue, 0, lngDataType, ByVal
strDataString, lngDataLength)
If lngResult <> ERROR_SUCCESS Then
GetRegistryString = "Error"
lngResult = RegCloseKey(lngHandle)
Exit Function
End If
strDataString = Left(strDataString, lngDataLength)
'Clean the string in a way that works for either registry key option
used in GetAcrobatReaderShellPath()
'Remove a doublequote from the beginning of the string, if present
If Len(strDataString) > 0 Then
If Left(strDataString, 1) = Chr(34) Then strDataString =
Right(strDataString, Len(strDataString) - 1)
End If
'Delete an extra character if present
If Right(strDataString, 3) <> "exe" And Len(strDataString) > 0 Then
strDataString = Left(strDataString, Len(strDataString) - 1)
'Remove a doublequote from the end of the string, if present
If Len(strDataString) > 0 Then
If Right(strDataString, 1) = Chr(34) Then strDataString =
Left(strDataString, Len(strDataString) - 1)
End If
'Make sure the string ends with "exe"
If Right(strDataString, 3) = "exe" Then
GetRegistryString = Left(strDataString, lngDataLength)
Else
GetRegistryString = "Error"
End If
lngResult = RegCloseKey(lngHandle)
End Function
'----
Public Function GetAcrobatReaderShellPath() As String
'Note: The better key to use may be HKEY_CLASSES_ROOT\Software\Adobe
\Acrobat\Exe
'since a user might have Acrobat installed and uses it instead of
Acrobat Reader
'If Acrobat is not installed it seems to get set to the Acrobat Reader
path
'GetAcrobatReaderShellPath = GetRegistryString(HKEY_LOCAL_MACHINE,
"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe",
"")
GetAcrobatReaderShellPath = GetRegistryString(HKEY_CLASSES_ROOT,
"Software\Adobe\Acrobat\Exe", "")
End Function
'--End Module Code
Also, is there an even better registry key to use?
Thanks,
James A. Fortune
(e-mail address removed)
(e-mail address removed)
code posted by John deKrafft. Does anyone see any problems with this
code running on various Windows OS's?
'--Begin Module Code
'Support functions and constants for reading a string from the
registry
'I have modified the code posted by John deKrafft slightly
'----
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String,
ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As
Long) As Long
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
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long)
As Long
Public Const SYNCHRONIZE As Long = &H100000
Public Const STANDARD_RIGHTS_ALL As Long = &H1F0000
Public Const KEY_QUERY_VALUE As Long = &H1
Public Const KEY_SET_VALUE As Long = &H2
Public Const KEY_CREATE_SUB_KEY As Long = &H4
Public Const KEY_ENUMERATE_SUB_KEYS As Long = &H8
Public Const KEY_NOTIFY As Long = &H10
Public Const KEY_CREATE_LINK As Long = &H20
Public Const KEY_ALL_ACCESS As Long = ((STANDARD_RIGHTS_ALL Or _
KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or _
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not
SYNCHRONIZE))
Public Const ERROR_SUCCESS As Long = 0
Public Const HKEY_LOCAL_MACHINE As Long = &H80000002
Public Const HKEY_CLASSES_ROOT As Long = &H80000000 'Added
Public Function GetRegistryString(lngKey As Long, strSubKey As String,
strValue As String) As String
Dim lngDataType As Long
Dim lngDataLength As Long
Dim strDataString As String
Dim lngResult As Long
Dim lngHandle As Long
Const StringLength = 150
strDataString = Space(StringLength)
lngDataType = 0
lngDataLength = CLng(StringLength)
lngResult = RegOpenKeyEx(lngKey, strSubKey, 0, KEY_ALL_ACCESS,
lngHandle)
If lngResult <> ERROR_SUCCESS Then
GetRegistryString = "Error"
Exit Function
End If
lngResult = RegQueryValueEx(lngHandle, strValue, 0, lngDataType, ByVal
strDataString, lngDataLength)
If lngResult <> ERROR_SUCCESS Then
GetRegistryString = "Error"
lngResult = RegCloseKey(lngHandle)
Exit Function
End If
strDataString = Left(strDataString, lngDataLength)
'Clean the string in a way that works for either registry key option
used in GetAcrobatReaderShellPath()
'Remove a doublequote from the beginning of the string, if present
If Len(strDataString) > 0 Then
If Left(strDataString, 1) = Chr(34) Then strDataString =
Right(strDataString, Len(strDataString) - 1)
End If
'Delete an extra character if present
If Right(strDataString, 3) <> "exe" And Len(strDataString) > 0 Then
strDataString = Left(strDataString, Len(strDataString) - 1)
'Remove a doublequote from the end of the string, if present
If Len(strDataString) > 0 Then
If Right(strDataString, 1) = Chr(34) Then strDataString =
Left(strDataString, Len(strDataString) - 1)
End If
'Make sure the string ends with "exe"
If Right(strDataString, 3) = "exe" Then
GetRegistryString = Left(strDataString, lngDataLength)
Else
GetRegistryString = "Error"
End If
lngResult = RegCloseKey(lngHandle)
End Function
'----
Public Function GetAcrobatReaderShellPath() As String
'Note: The better key to use may be HKEY_CLASSES_ROOT\Software\Adobe
\Acrobat\Exe
'since a user might have Acrobat installed and uses it instead of
Acrobat Reader
'If Acrobat is not installed it seems to get set to the Acrobat Reader
path
'GetAcrobatReaderShellPath = GetRegistryString(HKEY_LOCAL_MACHINE,
"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe",
"")
GetAcrobatReaderShellPath = GetRegistryString(HKEY_CLASSES_ROOT,
"Software\Adobe\Acrobat\Exe", "")
End Function
'--End Module Code
Also, is there an even better registry key to use?
Thanks,
James A. Fortune
(e-mail address removed)
(e-mail address removed)