tags:

views:

691

answers:

3

Exact Duplicate:

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

How to check if MSWord 2003 0r 2007 is installed in the system using C# code?

A: 

One of the solution, i reckon there should be better if you google it. To Check whether Excel is installed or not, I use this c# code

Excel.Application app = new Excel.ApplicationClass();

if app == null that means excel is not installed on the machine.If you check the MSDN docs, you should be able to get the syntax for opening a word appln.

Cshah
I have the syntax for opening a word document. But if word is not installed.............
Sauron
I thought the new-operator returns an object in every case. So 'app' can't be null, right? There might be an exception if Word is not installed but I don't know yet.
Alex
+1  A: 

This code shows that a simple registry check will do the job.

Here is the code converted to C# (and slightly improved to use a using statement).

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");
    }
}

Note that it's not good enough to check C:\Program Files\Microsoft Office\ for the msword EXE file, as the user might have installed it somewhere else.

Noldorin
How can I get the version 2003 or 2007?
Sauron
A: 

Access registry, check HKLM/Software/Microsoft/Office ?

Marcus Lindblom