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

时间:2010-01-02 10:02:15

标签: c# .net powerpoint

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

4 个答案:

答案 0 :(得分: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);
}

要检查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对象模型,以防止恶意脚本。因此,无论如何,还要有强大的错误处理。

希望这有帮助!

答案 1 :(得分:1)

HKEY_CLASSES_ROOT \ MSPowerPoint \协议\ StdFileEditing \服务器

此键对于PowerPoint的所有安装都是相同的,并指向运行PowerPoint的可执行文件的安装目录。在检测是否已安装此产品时很有用,并且在安装未使用默认值时很适合确定安装Office产品的文件夹。

答案 2 :(得分:0)

我不确定这是否正确。但你可以使用这个

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");
}

答案 3 :(得分:0)

使用system.io命名空间中的“Exists Method”检查PowerPoint或PowerPoint查看器的EXE文件是否存在,该怎么办?

检查this