6

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?

Community
  • 1
  • 1
Sauron
  • 16,668
  • 41
  • 122
  • 174
  • http://www.google.de/search?hl=de&q=site%3Astackoverflow.com+How%20to%20check%20if%20MSWord%202003%200r%202007%20is%20installed%20in%20the%20system%20using%20C%23%20code%3F – Dirk Vollmar May 22 '09 at 14:30

2 Answers2

13

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
  • 144,213
  • 56
  • 264
  • 302
0

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.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
Cshah
  • 5,612
  • 10
  • 33
  • 37
  • I have the syntax for opening a word document. But if word is not installed............. – Sauron May 22 '09 at 12:53
  • 1
    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 Mar 30 '10 at 21:27