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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting Acrobat for PDF files

Status
Not open for further replies.

BobLaw

Programmer
Oct 2, 2000
27
0
0
US
Hello,

I am looking for some information on adding detection for Adobe Acrobat Reader on a users system during the startup of an application. I have a user interface made so they can view various PDF files on a CD, but I want to be able to detect if they have the viewer or not and install it if they do not.

If you know how to do this or a good place to look for this information please let me know.

Thanks.

 
We usually do the check on installation of the app using Wise Installer--we search local drives for acrord32.exe and then acrobat.exe if not found. If neither is there, we install Reader.

If you want to do it on app start up, I suppose you could check the registry (HKEY_CURRENT_USER/Software) for an entry under Adobe/Acrobat Reader, or Adobe/Acrobat.

nkoszyk
 
Nkoszyk is right about checking the registry. Acrobat stores its settings in [tt]HKEY_LOCAL_MACHINE\Software\Adobe[/tt]. You can test for this key or the "EULA" value under [tt]\Adobe\Acrobat Reader\4.0\AdobeViewer[/tt] (for version 4.0).

I tested the following but, as always, treat any code that reads or writes to the registry with certain care and use it at your own risk (especially code that uses next to no error checking).

[tt]
Global Const REG_SZ As Long = 1
Global Const REG_DWORD As Long = 4
Global Const HKEY_LOCAL_MACHINE = &H80000002
Global Const ERROR_NONE = 0
Global Const KEY_ALL_ACCESS = &H3F
Global Const REG_OPTION_NON_VOLATILE = 0

Declare Function RegCloseKey Lib "advapi32.dll" ( _
ByVal hKey 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 RegQueryValueExString 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

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

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

Declare Function RegSetValueExString Lib "advapi32.dll" Alias _
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As _
String, ByVal cbData As Long) As Long

Private Function QueryValueEx( _
ByVal lhKey As Long, _
ByVal szValueName As String, _
vValue As Variant _
) As Long
Dim cch As Long
Dim lrc As Long
Dim lType As Long
Dim lValue As Long
Dim sValue As String
On Error GoTo QueryValueExError
lrc = RegQueryValueExNULL _
(lhKey, szValueName, 0&, lType, 0&, cch)
If lrc <> ERROR_NONE Then Error 5
Select Case lType
Case REG_SZ:
sValue = String(cch, 0)
lrc = RegQueryValueExString _
(lhKey, szValueName, 0&amp;, lType, sValue, cch)
If lrc = ERROR_NONE Then
If Mid(sValue, cch, 1) = Chr(0) Then
vValue = Left$(sValue, cch - 1)
Else
vValue = Left$(sValue, cch)
End If
Else
vValue = Empty
End If
Case REG_DWORD:
lrc = RegQueryValueExLong _
(lhKey, szValueName, 0&amp;, lType, lValue, cch)
If lrc = ERROR_NONE Then vValue = lValue
Case Else
lrc = -1
End Select
QueryValueExExit:
QueryValueEx = lrc
MsgBox Error(Err)
Exit Function

QueryValueExError:
Resume QueryValueExExit
End Function

Public Function QueryValue( _
ByVal lpParentKey As Long, _
sKeyName As String, _
sValueName As String _
) As Variant
Dim lRetVal As Long
Dim hKey As Long
Dim vValue As Variant
lRetVal = RegOpenKeyEx _
(lpParentKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
lRetVal = QueryValueEx(hKey, sValueName, vValue)
RegCloseKey (hKey)
QueryValue = vValue

End Function

Private Sub Command1_Click()
Dim sKey As String
Dim sValue As String
Dim vSetting As Variant
sKey = &quot;Software\Adobe\Acrobat Reader\4.0\AdobeViewer&quot;
sValue = &quot;EULA&quot;
vSetting = QueryValue(HKEY_LOCAL_MACHINE, sKey, sValue)
If vSetting = 1 Then
Adobe$ = &quot;installed&quot;
Else
Adobe$ = &quot;not installed&quot;
End If
MsgBox &quot;Adobe Viewer is &quot; &amp; Adobe$
End Sub
[/tt]


VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Thanks, I actually ended up doing this...


Public Const HKEY_CLASSES_ROOT = &amp;H80000000
Public Const HKEY_CURRENT_USER = &amp;H80000001
Public Const HKEY_LOCAL_MACHINE = &amp;H80000002
Public Const HKEY_USERS = &amp;H80000003
Public Const HKEY_PERFORMANCE_DATA = &amp;H80000004
Public Const ERROR_SUCCESS = 0&amp;

Declare Function RegOpenKey Lib &quot;advapi32.dll&quot; Alias &quot;RegOpenKeyA&quot; (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long


Declare Function RegQueryValueEx Lib &quot;advapi32.dll&quot; Alias &quot;RegQueryValueExA&quot; (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

Public Function getstring(Hkey As Long, strPath As String, strValue As String)

Dim keyhand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
r = RegOpenKey(Hkey, strPath, keyhand)
lResult = RegQueryValueEx(keyhand, strValue, 0&amp;, lValueType, ByVal 0&amp;, lDataBufSize)


If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, &quot; &quot;)
lResult = RegQueryValueEx(keyhand, strValue, 0&amp;, 0&amp;, ByVal strBuf, lDataBufSize)


If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))


If intZeroPos > 0 Then
getstring = left$(strBuf, intZeroPos - 1)
Else
getstring = strBuf
End If
End If
End If
End Function


And called it like this for the PDF (also using it for Word/Excel)

CheckPDF = getstring(HKEY_CLASSES_ROOT, &quot;.pdf&quot;, &quot;&quot;)

(This will check the (Default) AcroExch.Document)

If CheckPDF <> &quot;AcroExch.Document&quot; Then

Do something...

Thanks for the help people.

Take care.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top