2009-06-09 20 views
11

Come posso verificare se Adobe Reader o Acrobat è installato nel sistema? anche come ottenere la versione? (Nel codice C#)Controllare che Adobe Reader sia installato (C#)?

+5

Se ciò che si vuole realmente fare è controllare se un visualizzatore PDF è installato sul sistema, NON cercare Adobe Reader. Io e alcuni dei miei colleghi stiamo usando Foxit Reader, che è molto meglio di Adobe Reader. – OregonGhost

risposta

21
using System; 
using Microsoft.Win32; 

namespace MyApp 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      RegistryKey adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe"); 
      if(null == adobe) 
      { 
       var policies = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Policies"); 
       if (null == policies) 
        return; 
       adobe = policies.OpenSubKey("Adobe"); 
      } 
      if (adobe != null) 
      { 
       RegistryKey acroRead = adobe.OpenSubKey("Acrobat Reader"); 
       if (acroRead != null) 
       { 
        string[] acroReadVersions = acroRead.GetSubKeyNames(); 
        Console.WriteLine("The following version(s) of Acrobat Reader are installed: "); 
        foreach (string versionNumber in acroReadVersions) 
        { 
         Console.WriteLine(versionNumber); 
        } 
       } 
      } 
     } 
    } 
} 
+2

Adobe lo sta mettendo da qualche altra parte o la mia macchina Windows8 lo ha in modo diverso, ha modificato il codice sopra per provare a trovare Adobe in 'Software.Policies' –

+0

ha funzionato molto bene su IE, Chrome e FF. –

+0

C'è un modo per controllare il codice C# se il lettore Adobe installato è aggiornato, o se è disponibile un nuovo aggiornamento? –

6

perche anche le persone che eseguono sistemi operativi a 64 bit e, potenzialmente, in esecuzione sia a 32 bit o versioni a 64 bit di adobe reader.

Il seguente codice è una versione modificata della soluzione postata di Abmv, ma ciò verificherà se le versioni a 64 bit del lettore Adobe vengono installate prima di verificare le versioni a 32 bit.

Spero che questo abbia senso! :-)

using System; 
using Microsoft.Win32; 

namespace MyApp 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      RegistryKey software = Registry.LocalMachine.OpenSubKey("Software"); 

      if (software != null) 
      { 
       RegistryKey adobe; 

       // Try to get 64bit versions of adobe 
       if (Environment.Is64BitOperatingSystem) 
       { 
        RegistryKey software64 = software.OpenSubKey("Wow6432Node"); 

        if (software64 != null) 
         adobe = software64.OpenSubKey("Adobe"); 
       } 

       // If a 64bit version is not installed, try to get a 32bit version 
       if (adobe == null) 
        adobe = software.OpenSubKey("Adobe"); 

       // If no 64bit or 32bit version can be found, chances are adobe reader is not installed. 
       if (adobe != null) 
       { 
        RegistryKey acroRead = adobe.OpenSubKey("Acrobat Reader"); 

        if (acroRead != null) 
        { 
         string[] acroReadVersions = acroRead.GetSubKeyNames(); 
         Console.WriteLine("The following version(s) of Acrobat Reader are installed: "); 

         foreach (string versionNumber in acroReadVersions) 
         { 
          Console.WriteLine(versionNumber); 
         } 
        } 
        else 
         Console.WriteLine("Adobe reader is not installed!"); 
       } 
       else 
        Console.WriteLine("Adobe reader is not installed!"); 
      } 
     } 
    } 
} 
+0

ha funzionato molto bene con me su IE, Chrome e FF. –

+0

C'è un modo per controllare il codice C# se il lettore Adobe installato è aggiornato, o se è disponibile un nuovo aggiornamento? –

6

L'unica soluzione che funziona per me è:

var adobePath = Registry.GetValue(
@"HKEY_CLASSES_ROOT\Software\Adobe\Acrobat\Exe", string.Empty, string.Empty); 

Poi ho verificare se è installato adobePath != null quindi Adobe reader.

In questo modo otterrò anche il percorso dell'eseguibile del lettore acrobat.

Problemi correlati