【问题标题】:Check Adobe Reader is installed (C#)?检查是否安装了 Adob​​e Reader (C#)?
【发布时间】:2009-06-09 09:16:42
【问题描述】:

如何查看系统是否安装了 Adob​​e reader 或 acrobat?还有如何获得版本? (在 C# 代码中)

【问题讨论】:

  • 如果您真正想做的是检查系统上是否安装了 PDF 查看器,请不要检查 Adob​​e Reader。我和我的一些同事正在使用 Foxit Reader,它比 Adob​​e Reader 好得多。

标签: c# adobe-reader


【解决方案1】:
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);
                    }
                }
            }
        }
    }
}

【讨论】:

  • Adobe 要么把它放在别的地方,要么我的 Windows8 机器有它不同,修改上面的代码尝试在 Software.Policies 中找到 Adob​​e
  • 如果安装的 adobe reader 是最新的,或者有新的更新可用,有没有办法检查 c# 代码?
  • 我卸载了acrobat,但是维护了注册表,并且版本(adobe变量)不为空并且有最新版本。
【解决方案2】:

唯一适合我的解决方案是:

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

然后我检查adobePath != null是否安装了Adobe阅读器。

这样我还可以获得 acrobat reader 可执行文件的路径。

【讨论】:

    【解决方案3】:

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

    以下代码是 Abmv 发布的解决方案的修改版本,但这将检查是否先安装 64 位版本的 adobe reader,然后再检查 32 位版本。

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

    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!");
                }
            }
        }
    }
    

    【讨论】:

    • 如果安装的 adobe reader 是最新的,或者有新的更新可用,有没有办法检查 c# 代码?
    猜你喜欢
    • 2017-01-05
    • 1970-01-01
    • 2015-01-02
    • 2010-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-12
    相关资源
    最近更新 更多