检查Adobe Reader是否已安装(C#)?

Sau*_*ron 11 c# adobe-reader

如何检查系统中是否安装了Adobe Reader或acrobat?还有如何获得版本?(在C#代码中)

abm*_*bmv 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);
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • Adobe要么把它放在其他地方,要么我的Windows8机器有不同的东西,修改上面的代码试图在`Software.Policies`中找到Adobe (2认同)

Sha*_* Yu 6

还请考虑运行64位操作系统且可能运行32位或64位版本的adobe reader的人.

以下代码是Abmv发布的解决方案的修改版本,但是在检查32位版本之前,这将检查是否首先安装了64位版本的adobe reader.

希望这是有道理的!:-)

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!");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


Pin*_*ani 6

对我有用的唯一解决方案是:

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

然后我检查是否adobePath != null安装了Adobe Reader.

这样我将获得acrobat reader可执行文件的路径.