Detect Acrobat Reader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eleven
    New Member
    • Mar 2008
    • 19

    Detect Acrobat Reader

    Hi,

    Got a problem detecting if Acrobat Reader is installed on a machine, would really appreciate your help.

    I've got a PDF Report that I export to a directory then open it with Acrobat Reader. I need to check if the PC has Acrobat Reader installed before I open it...

    I found this code but it's not working, i always get the messagebox even if the PC has the software installed.

    Code:
    string RegPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
                using (RegistryKey RegKey = Registry.LocalMachine.OpenSubKey(RegPath))
                {
                    foreach (string SW_Name in RegKey.GetSubKeyNames())
                    {
                        if (SW_Name == "Acrobat Reader")
                        {
                            System.Diagnostics.Process.Start(@"C:\\...\\CK1_" + txtEntNo.Text + ".pdf");
                        }
                        else
                        {
                            MessageBox.Show("You do NOT have Acrobat Reader installed on your machine...", "No Acrobat Reader");
                        }
                    }
                }
    The only other codes I could find online were JavaScript, i wanna do it in C#. I'm using WinForms!

    Thanks!
  • vekipeki
    Recognized Expert New Member
    • Nov 2007
    • 229

    #2
    Open regedit and go to the "HKEY_LOCAL_MAC HINE\SOFTWARE\M icrosoft\Window s\CurrentVersio n\Uninstall\" node. Then press Ctrl+F to search the subnodes for a string (e.g. "reader").

    In my registry (I'm using Reader 8.0), it is saved under "{AC76BA86-7AD7-1033-7B44-A81000000003}", so that is what you should detect instead of "Acrobat Reader". Try other versions to see what the GUID looks like.

    Other approach would be to go through all nodes in "HKEY_LOCAL_MAC HINE\SOFTWARE\M icrosoft\Window s\CurrentVersio n\Uninstall\" and try to find the one where the DisplayName contains "Adobe Reader".

    Additional note: it looks to me like your code is opening a MessageBox many times, once for each element of the loop. Change your code to check all nodes before deciding whether it is installed or not.

    Comment

    • Eleven
      New Member
      • Mar 2008
      • 19

      #3
      Thanks a lot Vekipeki!
      I just noticed now that my code pops up the message box for each element.. thanks once again, I'll try out your suggestions.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Couldn't you just run this inside a try/catch block?
        System.Diagnost ics.Process.Sta rt(@"C:\\...\\C K1_" + txtEntNo.Text + ".pdf");

        If there was no handler for .PDF files, I think it throws an Exception?
        Win32Exception: No application is associated with the specified file for this operation.


        Might be a better way to do this, since not everyone will use Acrobat to read PDFs(like 99% will, but still)

        Comment

        • Eleven
          New Member
          • Mar 2008
          • 19

          #5
          Originally posted by Plater
          Couldn't you just run this inside a try/catch block?
          System.Diagnost ics.Process.Sta rt(@"C:\\...\\C K1_" + txtEntNo.Text + ".pdf");

          If there was no handler for .PDF files, I think it throws an Exception?
          Win32Exception: No application is associated with the specified file for this operation.


          Might be a better way to do this, since not everyone will use Acrobat to read PDFs(like 99% will, but still)
          Thanks a lot Plater, I actually didn't think about doing it that way! It works perfectly!!!

          Comment

          Working...