473,608 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

API code to obtain Acrobat Reader Shell Path from the registry

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.d ll" Alias
"RegQueryValueE xA" (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.d ll" Alias
"RegOpenKey ExA" (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.d ll" (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_S UB_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_RIGH TS_ALL Or _
KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_ KEY Or _
KEY_ENUMERATE_S UB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK ) And (Not
SYNCHRONIZE))
Public Const ERROR_SUCCESS As Long = 0
Public Const HKEY_LOCAL_MACH INE As Long = &H80000002
Public Const HKEY_CLASSES_RO OT As Long = &H80000000 'Added

Public Function GetRegistryStri ng(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(StringLen gth)
lngDataType = 0
lngDataLength = CLng(StringLeng th)
lngResult = RegOpenKeyEx(ln gKey, strSubKey, 0, KEY_ALL_ACCESS,
lngHandle)
If lngResult <ERROR_SUCCES S Then
GetRegistryStri ng = "Error"
Exit Function
End If
lngResult = RegQueryValueEx (lngHandle, strValue, 0, lngDataType, ByVal
strDataString, lngDataLength)
If lngResult <ERROR_SUCCES S Then
GetRegistryStri ng = "Error"
lngResult = RegCloseKey(lng Handle)
Exit Function
End If
strDataString = Left(strDataStr ing, lngDataLength)
'Clean the string in a way that works for either registry key option
used in GetAcrobatReade rShellPath()
'Remove a doublequote from the beginning of the string, if present
If Len(strDataStri ng) 0 Then
If Left(strDataStr ing, 1) = Chr(34) Then strDataString =
Right(strDataSt ring, Len(strDataStri ng) - 1)
End If
'Delete an extra character if present
If Right(strDataSt ring, 3) <"exe" And Len(strDataStri ng) 0 Then
strDataString = Left(strDataStr ing, Len(strDataStri ng) - 1)
'Remove a doublequote from the end of the string, if present
If Len(strDataStri ng) 0 Then
If Right(strDataSt ring, 1) = Chr(34) Then strDataString =
Left(strDataStr ing, Len(strDataStri ng) - 1)
End If
'Make sure the string ends with "exe"
If Right(strDataSt ring, 3) = "exe" Then
GetRegistryStri ng = Left(strDataStr ing, lngDataLength)
Else
GetRegistryStri ng = "Error"
End If
lngResult = RegCloseKey(lng Handle)
End Function
'----

Public Function GetAcrobatReade rShellPath() As String
'Note: The better key to use may be HKEY_CLASSES_RO OT\Software\Ado be
\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
'GetAcrobatRead erShellPath = GetRegistryStri ng(HKEY_LOCAL_M ACHINE,
"SOFTWARE\Micro soft\Windows\Cu rrentVersion\Ap p Paths\AcroRd32. exe",
"")
GetAcrobatReade rShellPath = GetRegistryStri ng(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
CD********@Fort uneJames.com
MP*******@Fortu neJames.com

Mar 8 '07 #1
5 7456
Do you really need to know the path? Can't you simply use ShellExecute
(http://www.mvps.org/access/api/api0018.htm at "The Access Web") or
Application.Fol lowHyperlink to open the PDF file?

Assuming you have an actual PDF file to which you can point, you can use the
code in http://www.mvps.org/access/api/api0023.htm or what Randy Birch has
at http://vbnet.mvps.org/code/system/findexecutable.htm (they both use the
same FindExecutable API call)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
<CD********@For tuneJames.comwr ote in message
news:11******** **************@ s48g2000cws.goo glegroups.com.. .
>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.d ll" Alias
"RegQueryValueE xA" (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.d ll" Alias
"RegOpenKey ExA" (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.d ll" (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_S UB_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_RIGH TS_ALL Or _
KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_ KEY Or _
KEY_ENUMERATE_S UB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK ) And (Not
SYNCHRONIZE))
Public Const ERROR_SUCCESS As Long = 0
Public Const HKEY_LOCAL_MACH INE As Long = &H80000002
Public Const HKEY_CLASSES_RO OT As Long = &H80000000 'Added

Public Function GetRegistryStri ng(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(StringLen gth)
lngDataType = 0
lngDataLength = CLng(StringLeng th)
lngResult = RegOpenKeyEx(ln gKey, strSubKey, 0, KEY_ALL_ACCESS,
lngHandle)
If lngResult <ERROR_SUCCES S Then
GetRegistryStri ng = "Error"
Exit Function
End If
lngResult = RegQueryValueEx (lngHandle, strValue, 0, lngDataType, ByVal
strDataString, lngDataLength)
If lngResult <ERROR_SUCCES S Then
GetRegistryStri ng = "Error"
lngResult = RegCloseKey(lng Handle)
Exit Function
End If
strDataString = Left(strDataStr ing, lngDataLength)
'Clean the string in a way that works for either registry key option
used in GetAcrobatReade rShellPath()
'Remove a doublequote from the beginning of the string, if present
If Len(strDataStri ng) 0 Then
If Left(strDataStr ing, 1) = Chr(34) Then strDataString =
Right(strDataSt ring, Len(strDataStri ng) - 1)
End If
'Delete an extra character if present
If Right(strDataSt ring, 3) <"exe" And Len(strDataStri ng) 0 Then
strDataString = Left(strDataStr ing, Len(strDataStri ng) - 1)
'Remove a doublequote from the end of the string, if present
If Len(strDataStri ng) 0 Then
If Right(strDataSt ring, 1) = Chr(34) Then strDataString =
Left(strDataStr ing, Len(strDataStri ng) - 1)
End If
'Make sure the string ends with "exe"
If Right(strDataSt ring, 3) = "exe" Then
GetRegistryStri ng = Left(strDataStr ing, lngDataLength)
Else
GetRegistryStri ng = "Error"
End If
lngResult = RegCloseKey(lng Handle)
End Function
'----

Public Function GetAcrobatReade rShellPath() As String
'Note: The better key to use may be HKEY_CLASSES_RO OT\Software\Ado be
\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
'GetAcrobatRead erShellPath = GetRegistryStri ng(HKEY_LOCAL_M ACHINE,
"SOFTWARE\Micro soft\Windows\Cu rrentVersion\Ap p Paths\AcroRd32. exe",
"")
GetAcrobatReade rShellPath = GetRegistryStri ng(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
CD********@Fort uneJames.com
MP*******@Fortu neJames.com

Mar 8 '07 #2
On Mar 8, 7:28 am, "Douglas J. Steele"
<NOSPAM_djsteel e@NOSPAM_canada .comwrote:
Do you really need to know the path? Can't you simply use ShellExecute
(http://www.mvps.org/access/api/api0018.htmat "The Access Web") or
Application.Fol lowHyperlink to open the PDF file?

Assuming you have an actual PDF file to which you can point, you can use the
code inhttp://www.mvps.org/access/api/api0023.htmor what Randy Birch has
athttp://vbnet.mvps.org/code/system/findexecutable. htm(they both use the
same FindExecutable API call)

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)
Besides the drawback of having a copyright notice for even some really
simple API functions at mvps.org, I can't imagine that the
FindExecutable API is any more reliable than having the actual path in
hand. I try not to look at or use much mvps.org code but that's
basically to prompt me to find different ways of doing things rather
than from any philosophical differences. Using FollowHyperlink is a
good idea, but it's not one that I expect to use anytime soon. I
think I'll use more mvps.org code in the future due to the contents of
a fortune cookie I read recently, but I'll not be using much, and not
soon. Thanks for pointing out some alternate methods. I'll just test
what I wrote on the OS's here.

James A. Fortune
CD********@Fort uneJames.com

Mar 8 '07 #3
<CD********@For tuneJames.comwr ote in message
news:11******** *************@8 g2000cwh.google groups.com...
On Mar 8, 7:28 am, "Douglas J. Steele"
<NOSPAM_djsteel e@NOSPAM_canada .comwrote:
>Do you really need to know the path? Can't you simply use ShellExecute
(http://www.mvps.org/access/api/api0018.htmat "The Access Web") or
Application.Fo llowHyperlink to open the PDF file?

Assuming you have an actual PDF file to which you can point, you can use
the
code inhttp://www.mvps.org/access/api/api0023.htmor what Randy Birch has
athttp://vbnet.mvps.org/code/system/findexecutable. htm(they both use the
same FindExecutable API call)

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)

Besides the drawback of having a copyright notice for even some really
simple API functions at mvps.org,
That strikes me as a petty complaint. You're free, of course, to go to MSDN,
read the specs for the API and write your own code.
I can't imagine that the
FindExecutable API is any more reliable than having the actual path in
hand.
FindExecutable gives you the actual path, and it's a heck of a lot simpler
code than speleunking through the registry. YMMV.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

Mar 8 '07 #4
On Mar 8, 5:02 pm, "Douglas J. Steele"
<NOSPAM_djsteel e@NOSPAM_canada .comwrote:
<CDMAPos...@For tuneJames.comwr ote in message

news:11******** *************@8 g2000cwh.google groups.com...


On Mar 8, 7:28 am, "Douglas J. Steele"
<NOSPAM_djsteel e@NOSPAM_canada .comwrote:
Do you really need to know the path? Can't you simply use ShellExecute
(http://www.mvps.org/access/api/api0018.htmat"T he Access Web") or
Application.Fol lowHyperlink to open the PDF file?
Assuming you have an actual PDF file to which you can point, you can use
the
code inhttp://www.mvps.org/access/api/api0023.htmorwh at Randy Birch has
athttp://vbnet.mvps.org/code/system/findexecutable. htm(theyboth use the
same FindExecutable API call)
--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)
Besides the drawback of having a copyright notice for even some really
simple API functions at mvps.org,

That strikes me as a petty complaint. You're free, of course, to go to MSDN,
read the specs for the API and write your own code.
I'll do that. I think it's petty to put the copyright notice on any
of the code, except that it's "especially " petty to put it on simple
code, but I believe the authors have the right to do so. I have the
right not to use code with such restrictions. Maybe I'm being petty.
>
I can't imagine that the
FindExecutable API is any more reliable than having the actual path in
hand.

FindExecutable gives you the actual path, and it's a heck of a lot simpler
code than speleunking through the registry. YMMV.
The speleunking only has to be done once. It just works after that.
I wouldn't be surprised if the FindExecutable API uses the same kind
of key path to get its results although I haven't checked the docs.
You suggest that the mvps.org code is more reliable. That might be
true. I don't write error-free code, but I've also seen silly errors
posted in newsgroups by some of the regulars at mvps.org. I would
never use mvps.org code in an application blindly without checking it
out first. I advise the same for others who use code I post. I think
the way we avoid using each other's code has been a positive thing so
far. I respect your ability and willingness to answer newsgroup
posts. I like to work things out for myself. That should be apparent
to everyone by now. My guess is that others who read what we post
understand the dynamics of what is happening better than we do. We're
too busy concentrating on answers. I'm suggesting that for some
problems in the future we work together to obtain the best possible
combination of ideas to solve them.

James A. Fortune
CD********@Fort uneJames.com

P.S., the part about the fortune cookie was sincere. I don't let
fortune cookies tell me how to live, but sometimes they shed light on
hidden truth.

Mar 8 '07 #5
CD********@Fort uneJames.com wrote:
>I don't let
fortune cookies tell me how to live, but sometimes they shed light on
hidden truth.
I read of an interesting problem involving fortune cookies a while
back. Turns out many more people than usual chose the winning numbers
in a lottery, possibly in New Jersey. The lottery folks were highly
suspicious of this thinking that somehow "a fix was in." Turns out
that almost all of those people chose their numbers from the back of
the slip of paper of fortune cookies. That in turn was followed up to
the one fortune cookie vendor who shrugged and said he prints
thousands of slips with the same number on the back.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Mar 9 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
12581
by: Chris | last post by:
Hello all, I wish to automate printing of PDF documents in a C# application. Is there an Adobe .net object? I tried to create a reference to the COM Object Adobe Type Library, but I get error "Exception from HRESULT 0x80131019" Thanks Chris
0
1914
by: Andrew | last post by:
My VB Application opens an Access Report and has an option to generate the report in PDF once the report is closed. This is accomplished by: - Switching over to the Acrobat Printer ( i.e. PDFWriter ) from the default printer. - Setting a string type sub key ( PDFFilename ) in the registry HKEY_CURRENT_USER\Software\Adobe\Acrobat PDFWriter ) to store the PDF in a user selected directory with a filename that's determined by VB codes. -...
4
7328
by: Andrew | last post by:
My VB Application opens an Access Report and has an option to generate the report in PDF once the report is closed. This is accomplished by: - Switching over to the Acrobat Printer (i.e. PDFWriter) from the default printer. - Setting a string type sub key "PDFFilename" in the registry "HKEY_CURRENT_USER\Software\Adobe\Acrobat PDFWriter" to store the PDF in a user selected directory with a filename that's determined by VB codes.
2
3658
by: jimfortune | last post by:
I have modified my GetAcroPath function to: Function GetAcroDir() As String Const LatestVer = 7 Dim strAcroDir(LatestVer - 2) As String Dim I As Integer strAcroDir(1) = "C:\Program Files\Adobe\Acrobat 3.0\Reader\" strAcroDir(2) = "C:\Program Files\Adobe\Acrobat 4.0\Reader\" strAcroDir(3) = "C:\Program Files\Adobe\Acrobat 5.0\Reader\"
5
2185
by: Haydnw | last post by:
Hi, I have the code below as code-behind for a page which displays two images. My problem is with the second bit of code, commented as " 'Portfolio image section". Basically, the SQL query gets details of a random image from an access database. I know this works because when I run the query in access, it picks a different image each time (or close enough). However, when I view the .aspx page that this code-behind is for, it always picks...
1
2820
by: John F | last post by:
Hi, I would like to open a pdf file using acrobat reader form a vb.net application. Is there a vb method to do this or do I need to run a shell command? If I need to run a shell command how do determine the executable path for for acrobat reader?
3
6588
by: moroni | last post by:
No problem 2 set Access up to get address data from tblClients then to use a form as a letterhead and to keyboard in the letter content then save the letter to a tblCorrespondence Get a scanner. Scan in your letters received to pdf format.Now insert in a form Adobe Acrobat Control For ActiveX (the pdf.ocx). Set the src property of the ActiveX control to the path of the pdf file you want to view. No problem it all works fine. Now try to...
10
10342
by: Mauro | last post by:
I'm trying to use the following VB function to transform a pdf document to a tiff one: http://forums.microsoft.com/msdn/showpost.aspx?postid=1665127&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=1 Private Sub savePDFtoTIF(ByVal fullPathPDF As String, ByVal fullPathTIF As String) Dim PDFApp As Acrobat.AcroApp Dim PDDoc As Acrobat.CAcroPDDoc Dim AVDoc As Acrobat.CAcroAVDoc Dim JSObj As Object
0
1813
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi all people, everybody, We have multiple versions of Acrobat Reader from 5.x to 8.x, I want to create a method in C# or VB.NET to check to see if the registry key for the versions exists, and if so uninstall it, then install the latest
0
8063
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8003
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6817
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.