代码之家  ›  专栏  ›  技术社区  ›  Firoz

如何检查计算机上是否安装了PowerPoint或Point Viewer?

  •  2
  • Firoz  · 技术社区  · 16 年前

    我需要播放PowerPoint幻灯片,但首先我要检查是否在计算机上安装了PowerPoint或查看器。我怎样才能用.NET做到这一点?

    4 回复  |  直到 14 年前
        1
  •  6
  •   Josh    16 年前

    这取决于您是否试图告诉您是否可以查看演示文稿(*.ppt、*.pptx等),或者您是否可以访问PowerPoint对象模型。

    要检查PPT文件是否有关联的处理程序,可以执行以下操作:

    // using Microsoft.Win32;
    private bool CheckPowerPointAssociation() {
        var key = Registry.ClassesRoot.OpenSubKey(".ppt", false);
        if (key != null) {
            key.Close();
            return true;
        }
        else {
            return false;
        }
    }
    
    if (CheckPowerPointAssociation()) {
        Process.Start(pathToPPT);
    }
    

    要检查PowerPoint COM对象模型是否可用,可以检查以下注册表项。

    // using Microsoft.Win32;
    private bool CheckPowerPointAutomation() {
        var key = Registry.ClassesRoot.OpenSubKey("PowerPoint.Application", false);
        if (key != null) {
            key.Close();
            return true;
        }
        else {
            return false;
        }
    }
    
    if (CheckPowerPointAutomation()) {
        var powerPointApp = new Microsoft.Office.Interop.PowerPoint.Application();
        ....
    }
    

    但是,请注意,在这两种情况下,它都只能很好地指示PowerPoint的可用性。例如,卸载可能没有完全删除所有跟踪。同样,在我多年销售Outlook加载项的经验中,我也看到过某些防病毒程序会干扰COM对象模型,从而破坏保护程序免受恶意脚本的攻击。因此,在任何情况下,都有强大的错误处理能力。

    希望这有帮助!

        2
  •  1
  •   BtilEntrails    14 年前

    hkey_classes_root\mspowerpoint\protocol\stdfileediting\server

    对于PowerPoint的所有安装,此键都是相同的,并指向可执行文件运行PowerPoint的安装目录。在检测是否安装了此产品时非常有用,并且在安装未使用默认值时,可以很好地确定Office产品安装在哪个文件夹中。

        3
  •  0
  •   Anuraj    16 年前

    我不确定这是正确的方法。但是你可以用这个

    try
    {
        //It will throw a WIN32 Exception if there is no associated 
        //application available to open the file.
        Process p = Process.Start("C:\\Sample.pptx");
    }
    catch (Win32Exception ex)
    {
        MessageBox.Show("Powerpoint or Powerpoint viewer not installed\n");
    }
    
        4
  •  0
  •   Peter Mortensen Pieter Jan Bonestroo    16 年前

    使用system.io命名空间中的“exists method”检查PowerPoint或PowerPoint查看器的exe文件是否存在?

    检查 this .