C#: How to know whether certain Office 2003 or 2007 application is installed?

后端 未结 2 1888
耶瑟儿~
耶瑟儿~ 2020-12-20 04:12

I need to know whether Microsoft Word, Excel, Outlook, Project, etc are installed in a Windows Forms .net 2.0 C# application.
The first attempt was by simply trying to

相关标签:
2条回答
  • 2020-12-20 04:29

    This should work, as described here. It's not a very elegant solution, though, as it is version specific and will break with the next office version. This example is forOffice 2003, so it won't work with Office 2007 without updating.

    const string ASSEMBLY2003 = "Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";  
    
    static bool IsAssemblyInstalled(string assembly)  
    {  
       try 
       {  
           s_assemblyExcel = Assembly.Load(assembly);  
           return true;  
       }   
       catch 
       {  
           return false;  
       }  
    } 
    
    0 讨论(0)
  • 2020-12-20 04:32

    You can use the MSI (Windows Installer) APIs to find out if the relevant product/package/component codes are present on the machine. These are fairly simple to use via P/Invoke.

    Alternatively, you can look in the registry. Word 2007, for example, puts its install location at HKLM\SOFTWARE\Microsoft\Office\12.0\Word\InstallRoot.

    This doesn't help you if you're planning on using the interop components, but it does tell you, with reasonable certainty, whether the various things are installed.

    0 讨论(0)
提交回复
热议问题