2009-06-09 19 views
11

Jak mogę sprawdzić, czy program Adobe Reader lub program acrobat jest zainstalowany w systemie? także jak uzyskać wersję? (W kodu C#)Czy zainstalowany jest Adobe Reader (C#)?

+5

Jeśli naprawdę chcesz zrobić, to sprawdzić, czy przeglądarka plików PDF jest zainstalowana w systemie, NIE sprawdzaj programu Adobe Reader. Ja i niektórzy moi współpracownicy używają Foxit Reader, który jest o wiele lepszy niż Adobe Reader. – OregonGhost

Odpowiedz

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 umieszcza to gdzieś indziej lub moja maszyna z Windows8 ma to inaczej, zmodyfikowałem powyższy kod, aby spróbować znaleźć Adobe w 'Software.Policies' –

+0

działało świetnie na IE, Chrome i FF. –

+0

Czy istnieje sposób sprawdzenia kodu C#, jeśli zainstalowany czytnik Adobe jest aktualny lub dostępna jest nowa aktualizacja? –

6

Należy również wziąć pod uwagę osoby uruchomiony system operacyjny 64bit i 32bit potencjalnie działa zarówno wersje 64-bitowe lub czytnika Adobe.

Poniższy kod jest zmodyfikowaną wersją dostarczonego rozwiązania Abmv, ale to sprawdzi, czy 64-bitowe wersje czytnika Adobe zostały zainstalowane najpierw przed sprawdzeniem wersji 32-bitowych.

Mam nadzieję, że to ma sens! :-)

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

działał świetnie na IE, Chrome i FF. –

+0

Czy istnieje sposób sprawdzenia kodu C#, jeśli zainstalowany czytnik Adobe jest aktualny lub dostępna jest nowa aktualizacja? –

6

Jedynym rozwiązaniem, które pracuje dla mnie jest:

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

Potem sprawdzić czy jest zainstalowany adobePath != null następnie Adobe Reader.

W ten sposób otrzymam również ścieżkę do pliku wykonywalnego programu Acrobat Reader.

Powiązane problemy