سؤال

كيف يمكنني التحقق مما إذا كان Adobe Reader أو Acrobat مثبتا في النظام؟ أيضا كيفية الحصول على الإصدار؟ (في كود C #)

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

يرجى أيضا التفكير في الأشخاص الذين يقومون بتشغيل أنظمة تشغيل 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!");
            }
        }
    }
}

الحل الوحيد الذي يعمل بالنسبة لي هو:

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

ثم تحقق ما إذا كان adobePath != null ثم تم تثبيت Adobe Reader.

بهذه الطريقة سأحصل أيضا على الطريق إلى قارئ Acrobat القابل للتنفيذ.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top