Click here to Skip to main content
15,868,164 members
Articles / Productivity Apps and Services / Microsoft Office / Microsoft Word
Alternative
Tip/Trick

How to Check Whether Word is Installed in the System or Not

Rate me:
Please Sign up or sign in to vote.
5.00/5 (8 votes)
24 Dec 2013CPOL 17.5K   9   5
This is an alternative for "How to Check Whether Word is Installed in the System or Not"

Introduction 

It is common to need to work with various Office applications using the Microsoft.Office.Interop.xxx namespaces where xxx is the Office application, e.g. Microsoft.Office.Interop.Word in order to do so, you must ensure that the appropriate application is installed on the client machine.  

Background 

Having read both of Tadit's excellent tips I decided that I would make a simple utility class to handle the logic for me - allowing me to reuse the code and optomise it over time if needed.

Using the code 

The utility class was added to my standard library, so that I can use it in multiple projects. 

C#
using System;

namespace Me.Office.Common
{
    /// <summary>
    /// A group of Microsoft Office Utility methods
    /// </summary>
    public static class OfficeUtils
    {
        /// <summary>
        /// A utility method to check if Word is installed or not
        /// </summary>
        /// <returns>A Boolean value of whether Word is installed or not</returns>
        public static bool isWordInstalled()
        {
            return isApplicationInstalled("Word.Application");
        }
 
        /// <summary>
        /// A utility method to check if Excel is installed or not
        /// </summary>
        /// <returns>A Boolean value of whether Excel is installed or not</returns>
        public static bool isExcelInstalled()
        {
            return isApplicationInstalled("Excel.Application");
        }
 
        /// <summary>
        ///
        /// </summary>
        /// <param name="applicationName">The name of the application to be checked</param>
        /// <returns>A Boolean value of whether Application is installed or not</returns>
        private static bool isApplicationInstalled(string applicationName)
        {
            Type officeType = Type.GetTypeFromProgID(applicationName);
 
            return officeType != null;
        }
    }
}

This can be used in any other project as long as it is referenced correctly 

C#
using Me.Office.Common;

namespace Me.TestHarness
{
  class Program
  {
    static void Main(string[] args)
    {
      bool isWordInsatlled = OfficeUtils.isWordInstalled();
      bool isExcelInsatlled = OfficeUtils.isExcelInstalled();
    }
  }
}

History 

  • 23 December 2013 - First version published . 
  • 24 December 2014 - Fixed namespace reference 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Program Manager
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionQuestion Pin
Member 968772927-Dec-13 5:21
Member 968772927-Dec-13 5:21 
AnswerRe: Question Pin
Reiss27-Dec-13 6:53
professionalReiss27-Dec-13 6:53 
QuestionThanks Pin
Ken of Kendoria26-Dec-13 4:56
professionalKen of Kendoria26-Dec-13 4:56 
QuestionNice work. Pin
Pravin Patil, Mumbai24-Dec-13 22:53
Pravin Patil, Mumbai24-Dec-13 22:53 
QuestionNice! Pin
Volynsky Alex23-Dec-13 9:24
professionalVolynsky Alex23-Dec-13 9:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.