Check if any PDF reader is installed

I have a Help function in my Application , which consists of one webbrowser control . That the webbrowser control populated with a .pdf file , the source for this .pdf file is our own website.

The problem is that everyone will not have PDF Reader installed on their machine, so I want to check if it is installed: Yes or No. I searched on the Internet, and I basically saw that users on Stackoverflow, where they want to check if Adobe Reader installed, is not what I want. I need to know if PDF PDF Reader installed on the machine.

I found the following code that might help me:

 public void CheckPdfReaderAvailable() { RegistryKey key = Registry.ClassesRoot.OpenSubKey(".pdf"); Assert.IsNotNull(key); } 

As I see the above code, my thoughts are that the code checks to see if the registry .pdf format knows, but I'm not sure.

Can someone tell me how to use the code above or provide me with an example on how I should fix this problem?

Thanks in advance!

EDIT:

The following answer helped me: stack overflow

Another way to solve this problem is to add the PDF reader lite to the prerequisites and first install the users, you do not need to check the PDF reader, because you know that it is installed, unless you could say that the user’s error was that they cannot use the help function because you offered them an easy way to install a PDF reader using a published project.

+6
source share
3 answers

In addition, whether it is useful to know or not, you can check the following registry key:

HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/pdf

This will be a CLSID entry that points to the default application class identifier.

If there is no registry key or CLSID , then the MIME type is unknown, or there is no default application for processing MIME type application/pdf files.

+5
source

You can request the registry directly, but the recommended solution is to use the IQueryAssociations interface to find out if there is a program registered to open PDF files. An example can be found on pinvoke.net .

+2
source

Implementation of the C # approach proposed by John Willems (will not recognize Edge as the default viewer for a version other than N Windows version 10):

  private bool CanOpenPDFFiles { get { bool CLSIDpresent = false; try { using (Microsoft.Win32.RegistryKey applicationPDF = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(@"MIME\Database\Content Type\application/pdf")) { if (applicationPDF != null) { var CLSID = applicationPDF.GetValue("CLSID"); if (CLSID != null) { CLSIDpresent = true; } } } } catch (Exception) { } return CLSIDpresent; } } 
0
source

All Articles