检查是否安装了 Adobe Reader (C#)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/969027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Check Adobe Reader is installed (C#)?
提问by Sauron
How can I check whether Adobe reader or acrobat is installed in the system? also how to get the version? ( In C# code )
如何检查系统中是否安装了 Adobe reader 或 acrobat?还有怎么获取版本?(在 C# 代码中)
采纳答案by abmv
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);
}
}
}
}
}
}
回答by Shane Yu
Please also consider people running 64bit operating systems and potentially running either 32bit or 64bit versions of adobe reader.
还请考虑运行 64 位操作系统并可能运行 32 位或 64 位版本的 adobe reader。
The following code is a modified version of Abmv's posted solution, but this will check to see if 64bit versions of adobe reader are installed first before checking for 32bit versions.
以下代码是 Abmv 发布的解决方案的修改版本,但这将检查是否先安装了 64 位版本的 adobe reader,然后再检查 32 位版本。
Hope this makes sense! :-)
希望这是有道理的!:-)
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!");
}
}
}
}
回答by Pinte Dani
The only solution which works for me is:
对我有用的唯一解决方案是:
var adobePath = Registry.GetValue(
@"HKEY_CLASSES_ROOT\Software\Adobe\Acrobat\Exe", string.Empty, string.Empty);
Then I check if adobePath != null
then Adobe reader is installed.
然后我检查是否adobePath != null
安装了 Adobe reader。
This way I will get also the path to the acrobat reader executable.
这样我也将获得 acrobat reader 可执行文件的路径。