本文介绍了如何检查机器上是否安装了 PowerPoint 或 Point Viewer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要播放 PowerPoint 幻灯片,但首先我想检查机器上是否安装了 PowerPoint 或查看器.我如何使用 .NET 做到这一点?

I need to play PowerPoint slides but first I want to check whether PowerPoint or viewer is installed on the machine or not. How can I do that using .NET?

推荐答案

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

It depends on whether you are trying to tell whether you can view a presentation (*.ppt, *.pptx, etc) or whether you can access the PowerPoint object model.

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

To check whether there is an associated handler for ppt files, you can do the following:

// 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 对象模型是否可用,您可以检查以下注册表项.

To check whether the PowerPoint COM object model is available, you can check the following registry key.

// 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 对象模型,以防止恶意脚本.所以无论如何,也要有强大的错误处理能力.

Note, however, that in both cases it will only give you a pretty good indication of the availability of PowerPoint. For example, an uninstallation may not have fully removed all traces. Also in my experience selling an Outlook addin for years I've seen certain antivirus programs that interfere with the COM object model in a screwup effort to protect against malicious scripts. So in any case, have robust error handling as well.

希望这会有所帮助!

这篇关于如何检查机器上是否安装了 PowerPoint 或 Point Viewer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:50