检查MSWord是否已安装在系统中

Sau*_*ron 5 c# ms-word

完全重复:

C#:如何知道是否安装了某些Office 2003或2007应用程序?

如何使用C#代码检查系统中是否安装了MSWord 2003 0r 2007?

Nol*_*rin 12

此代码显示简单的注册表检查将完成此任务.

这是转换为C#的代码(稍微改进以使用using语句).

using Microsoft.Win32;

// Check whether Microsoft Word is installed on this computer,
// by searching the HKEY_CLASSES_ROOT\Word.Application key.
using (var regWord = Registry.ClassesRoot.OpenSubKey("Word.Application"))
{
    if (regWord == null)
    {
        Console.WriteLine("Microsoft Word is not installed");
    }
    else
    {
        Console.WriteLine("Microsoft Word is installed");
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,这是不够好,以检查C:\Program Files\Microsoft Office\mswordEXE文件,因为用户可能已经在其他地方安装了它.