【问题标题】:check Acrobat reader installed in pc and display installer检查 PC 中安装的 Acrobat 阅读器并显示安装程序
【发布时间】:2011-07-01 03:29:00
【问题描述】:

我的经理询问了包含 PDF 文件的自动播放 cd 并检查用户 pc 上是否安装了 adobe acrobat 是否安装了消息 apear 从 cd 安装此程序 我有 windows 应用程序来检查是否是 adob reader 或 acrobat是否安装在 pc 中我做得很好,但我想如果没有安装这个程序,acrobat reader 安装程序会从 cd 和用户安装这个程序。

 public Form1()
    {
        RegistryKey adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe");
        if (adobe != null)
        { 
            RegistryKey acroRead = adobe.OpenSubKey("Acrobat Reader");
            if (acroRead != null)
            { 
                string[] acroReadVersions = acroRead.GetSubKeyNames();
                MessageBox.Show("The following version(s) of Acrobat Reader are installed: ");

                foreach (string versionNumber in acroReadVersions)
                { 
                    MessageBox.Show(versionNumber);
                } 
            } 

        } 
        else
        { 
            MessageBox.Show("The following version(s) of Acrobat Reader arenot installed: ");

        } 

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    您需要调用安装程序进程。像这样的。

    Process myProcess = new Process();
    myProcess.StartInfo.FileName = "path to acrobat installer"; 
    myProcess.Start();
    

    更好的方法是为此在您的应用程序设置中添加自定义操作。

    【讨论】:

      【解决方案2】:

      有几种方法可以检查这一点。

      1/检查已安装的应用程序(win安装程序)

      每个 Windows 安装程序项目 (MSI) 都有一个升级代码和一个产品代码。 简而言之,产品代码定义了已安装应用程序的版本及其依赖项。不同版本的升级代码保持不变。 您可以搜索 acrobat reader 的产品代码并使用 windows installer dll 来检查它是否已安装。 codeproject 上有一些代码(搜索 MsiInterop),其中包含所有需要的 dllimports。

      2/ 保持简单。

      为什么不检查是否存在与具有 PDF 扩展名的文件关联的应用程序??
      如果有关联的应用程序(可能不是 Acrobat Reader,例如 foxit),则假设一切正常。 否则,启动指向http://get.adobe.com/reader/的浏览器

      这样,您的应用程序不会对用户选择的 PDF 阅读器承担责任。

      【讨论】:

        【解决方案3】:

        在 C# 中访问 Windows 安装程序:

        public enum InstallState
        {
               NotUsed = -7,
               BadConfig = -6,
               Incomplete = -5,
               SourceAbsent = -4,
               MoreData = -3,
               InvalidArg = -2,
               Unknown = -1,
               Broken = 0,
               Advertised = 1,
               Removed = 1,
               Absent = 2,
               Local = 3,
               Source = 4,
               Default = 5
        }   
        [System.Runtime.InteropServices.DllImport("msi.dll", CharSet = CharSet.Unicode)]
        internal static extern InstallState MsiQueryProductState(string szProduct);
        

        如果您知道 Adob​​e Acrobat 的产品代码,您可以查询其安装状态:

        bool acrobatInstalled = allAcrobatReaderProductCodes.Any(guid =>
        {
             var productCode = "{" + guid.ToString().ToUpper() + "}";
             var msiState = MsiQueryProductState(productCode);
             return msiState == InstallState.Local || msiState == InstallState.Default);
        });
        

        其中 allAcrobatReaderCodes 是所有 acrobat 阅读器产品代码的 IEnumerable。

        【讨论】:

          猜你喜欢
          • 2011-07-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-03-15
          • 2010-10-06
          • 2013-04-04
          相关资源
          最近更新 更多