【问题标题】:How can I check that PowerPoint or point viewer is installed on the machine?如何检查计算机上是否安装了 PowerPoint 或点查看器?
【发布时间】:2010-01-02 10:02:15
【问题描述】:

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

【问题讨论】:

  • 你的意思是包括open-office或者其他可以打开powerpoint的程序?
  • 你喜欢asp.net还是c#.net给出明确的信息

标签: c# .net powerpoint


【解决方案1】:

这取决于您是否试图判断是否可以查看演示文稿(*.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 对象模型,以防止恶意脚本。所以在任何情况下,也要有健壮的错误处理。

希望这会有所帮助!

【讨论】:

  • Office 2013 发生了变化。如果用户从未安装过以前版本的 Office,则 PowerPoint 2013 的注册表项是“PowerPoint.Application.15”。我仍在寻找一个好的现在微软更改了注册表项名称,解决了这个问题。
  • 虽然我没有“干净”的系统来验证这一点,但我只想说这似乎不太可能。总是有一个特定于版本的 ProgID(即 PowerPoint.Application.15)和一个非特定于版本的 ProgID (PowerPoint.Application),它们都指向同一个 CLSID。
  • 也许吧。我正在支持我们产品的用户,他与我共享他的屏幕,这样我就可以自己检查他的注册表。我们检查是否安装了 PPT 的测试失败了,因为没有“PowerPoint.Application”键。此用户似乎不是破坏他的 Office 注册表项的类型。我很想知道我错了。
【解决方案2】:

HKEY_CLASSES_ROOT\MSPowerPoint\protocol\StdFileEditing\server

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

【讨论】:

  • Office 2013 发生了变化。似乎如果用户从未安装过以前版本的 Office,那么注册表项是“ms-powerpoint”而不是“MSPowerPoint”。
【解决方案3】:

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

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】:

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

检查this

【讨论】:

  • 它会起作用吗?因为用户可以在他的系统中的任何位置安装应用程序。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-04
  • 2017-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多