【发布时间】:2010-01-02 10:02:15
【问题描述】:
我需要播放 PowerPoint 幻灯片,但首先我想检查机器上是否安装了 PowerPoint 或查看器。如何使用 .NET 做到这一点?
【问题讨论】:
-
你的意思是包括open-office或者其他可以打开powerpoint的程序?
-
你喜欢asp.net还是c#.net给出明确的信息
标签: c# .net powerpoint
我需要播放 PowerPoint 幻灯片,但首先我想检查机器上是否安装了 PowerPoint 或查看器。如何使用 .NET 做到这一点?
【问题讨论】:
标签: c# .net powerpoint
这取决于您是否试图判断是否可以查看演示文稿(*.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 对象模型,以防止恶意脚本。所以在任何情况下,也要有健壮的错误处理。
希望这会有所帮助!
【讨论】:
HKEY_CLASSES_ROOT\MSPowerPoint\protocol\StdFileEditing\server
此键对于所有 PowerPoint 安装都是相同的,并指向可执行文件运行 PowerPoint 的安装目录。非常适合用于检测是否已安装此产品,以及在安装未使用默认值时确定 Office 产品安装在哪个文件夹中。
【讨论】:
我不确定这是正确的方法。但是你可以用这个
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");
}
【讨论】:
如何使用 system.io 命名空间中的“Exists Method”检查 PowerPoint 或 PowerPoint 查看器的 EXE 文件是否存在?
检查this。
【讨论】: