65.9K
CodeProject 正在变化。 阅读更多。
Home

如何检查PowerPoint是否安装在系统中

2013年12月3日

CPOL

1分钟阅读

viewsIcon

17365

在关于Excel和Word的技巧之后,我们将探讨如何使用C#验证客户端系统中是否安装了PowerPoint。

引言

ExcelWord的技巧之后,我们将对Microsoft PowerPoint执行相同的操作。

如果您在应用程序中使用Microsoft.Office.Interop.PowerPoint进行PowerPoint相关操作,那么您必须检查客户端机器上是否安装了PowerPoint。本技巧将为您提供该方法。

背景

这段小代码是评论Marco Bertschi在我之前的技巧 (如何检查Excel是否安装在系统中) 之后的研究成果。非常感谢Marco。:)

很好,Tadit - 也许可以通过提供其他Office应用程序(Word等,甚至Visio或MS Project)的ProgID来改进它。

Using the Code

我们将使用Type类及其方法Type.GetTypeFromProgID Method (String)

获取与指定程序标识符(ProgID)关联的类型,如果加载Type时遇到错误,则返回null

返回值:

类型:System.Type

如果progID是注册表中的有效条目并且与该条目关联了类型,则返回与指定ProgID关联的类型;否则,返回null

对于PowerPointProgIDPowerpoint.Application。因此,使用以下代码来检查PowerPoint是否安装。

Type officeType = Type.GetTypeFromProgID("Powerpoint.Application");

if (officeType == null)
{
    // Powerpoint is not installed.   
    // Show message or alert that Powerpoint is not installed.
}
else
{
    // Powerpoint is installed.    
    // Continue your work.
}

历史

  • 2013年12月3日 - 首次提交版本以供审核。
© . All rights reserved.