如何检查计算机上是否安装了PowerPoint或点查看器?

Fir*_*roz 2 .net c# powerpoint

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

Jos*_*osh 6

这取决于您是否要尝试判断是否可以查看演示文稿(*.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);
}
Run Code Online (Sandbox Code Playgroud)

若要检查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();
    ....
}
Run Code Online (Sandbox Code Playgroud)

但请注意,在这两种情况下,它只能为您提供PowerPoint的可用性.例如,卸载可能没有完全删除所有跟踪.另外根据我多年来销售Outlook插件的经验,我看到某些防病毒程序会干扰COM对象模型,以防止恶意脚本.因此,无论如何,还要有强大的错误处理能力.

希望这可以帮助!