# VBForums CodeBank > CodeBank - Visual Basic .NET >  How to check if word , excel ,access or any office application is Installed ??

## maged

first of all you must import namespace [ microsoft.win32] to access the registery classes in .net framwork

then this code will check the regestery if the application is installed or not 


VB Code:
Dim TargetKey As RegistryKey
        TargetKey = Registry.ClassesRoot.OpenSubKey("word.application")
        If TargetKey Is Nothing Then
            MsgBox("Word application is not found")
        Else    'key is found
            MsgBox("Word application is found")
            TargetKey.Close()
        End If

you can change the string in the second line from "word.application" to "excel.application" or "access.application" in order to check for different components. 

rgds

----------


## RobDog888

You could also test for it without having to work around any possible user permissions to the reqistry by just error trapping the creation of an object of the type your testing for.

 :Wink: 

VB Code:
Private bInstalled As Boolean
 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim oApp As Object = CreateObject("Outlook.Application")
            bInstalled = True
        Catch
            bInstalled = False
            MessageBox.Show("Office Application not installed!", "Office Installed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
End Sub

----------


## maged

well that is another way , 

but mine is more effecient with the drawback of required permession to access registery keys.

why it is effecient ???
because 
1 - raising exceptions may take a while in processing, direct code is faster

2 - try catch statemnt is slower than direct code execution

3 - if the office application is installed, then you are creating a new instance of the application without any use. also you didn't dispose it from the memory after monitoring that it is succesffuly created. 

that is all the drawbacks i can find in your code, although this method is more guranteed due to permessions required to access registery.

anyway, i am only responding to your reply because i like to urgue, but in the matter of fact you are far more experienced than me . only to the current moment, i will do my best   :Wink:  

rgds

----------


## RobDog888

Oh good, I like to argue too!  :Big Grin:  Jk. I only posted another possibility because I though it may be helpful to have more then one way to skin a cat.  :Smilie: 

With my method it has advantages over yours for similar reasons.

1. - Accessing the registry should be done in a Try Catch block to trap for registry permissions issues.

2. - Try Catch may be slower but since it is risky to directly attempt to read the registry or create and office app object both should be in a Try Catch block.  :Wink: 

3. - Yes, I am creating an instance of Outlook, but if your testing to see if Outlook is installed its because your going to be using it in your code or why test for it being installed. 

I didnt add allot of clean up code because it was only a logic example. 

You are getting better though and are catching up to me.  :EEK!:   :Thumb:

----------


## maged

> You are getting better though and are catching up to me.



ohhhh, thank u   :Blush:  

 :wave:

----------


## uniquegodwin

This can only check if office applications are installed.It cant check any other applications right? Can it?

----------


## RobDog888

With my code you would just change the one line of code with the "CreateObject("Outlook.Application")" to pass the application and type you want to test for.

VB Code:
Dim oApp As Object = CreateObject("SomeProgram.ApplicationType")

----------

