?
Solved

How do I check for existence of Powerpoint and Excel from VB app

Posted on 2004-08-30
8
Medium Priority
?
161 Views
Last Modified: 2010-04-23
I have a vb .net application that creates powerpoint and excel presentations.  I works fine, unless the user doesn't have powerpoint and excel installed on their computers.  How do I check for that so that I can issue a warning to the user?

Thanks!
0
Comment
Question by:spmcmorrow
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11931488
One way would be to check the listing of programs that appear in the "Add/Remove Programs" listing you see in the control panel.  This is done by enumerating the "Software\Microsoft\Windows\CurrentVersion\Uninstall" key under the LocalMachine area.  The "DisplayName" value is the installed application.

On my system there is only one entry for the whole office suite, "Microsoft Office XP Professional".  I'm not sure how it looks for other versions of Office.

Below is an application that populates a ListBox with all installed applications on the system.  I'm not sure if Administrator rights are required to use this approach.

Regards,

Idle_Mind

Imports Microsoft.Win32

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.SuspendLayout()
        '
        'ListBox1
        '
        Me.ListBox1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.ListBox1.Location = New System.Drawing.Point(8, 8)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(288, 160)
        Me.ListBox1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(304, 182)
        Me.Controls.Add(Me.ListBox1)
        Me.Name = "Form1"
        Me.Text = "Add/Remove Program Listing"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim rk As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
            Dim sk As String
            Dim appKey As RegistryKey
            Dim displayNameValue As Object
            Dim displayName As String
            ListBox1.Sorted = True
            ListBox1.BeginUpdate()
            If Not (rk Is Nothing) Then
                For Each sk In rk.GetSubKeyNames
                    appKey = rk.OpenSubKey(sk)
                    displayNameValue = appKey.GetValue("DisplayName")
                    If Not (displayNameValue Is Nothing) Then
                        ListBox1.Items.Add(CType(displayNameValue, String))
                    End If
                Next
            End If
            ListBox1.EndUpdate()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Error Accessing Registry")
        End Try
    End Sub

End Class
0
 
LVL 8

Accepted Solution

by:
wguerram earned 500 total points
ID: 11937332
Try this:

If you get an error it means the activeX does not exist:        

        Dim x As Object
        Try
            x = CreateObject("PowerPoint.Application")
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            x = Nothing
        End Try

0
 
LVL 8

Expert Comment

by:wguerram
ID: 11937335
The same for excel

 Dim x As Object
        Try
            x = CreateObject("Excel.Application")
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            x = Nothing
        End Try
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 11942293
I like the solution that wguerram has shown, since registry keys are different depending on what version of Excel and PowerPoint that the user has installed.  Generic solutions are the best.

Bob
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11942502
I agree...wguerram's method will be much cleaner.  This is why I usually preface my posts with "One way would be to..." instead of "The best way would be to..."

=)
Idle_Mind
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11942525
That's true, but the "one way" could be the "best way" for you *GRIN*.  It's all in the eye of the beholder.

Bob
0
 

Author Comment

by:spmcmorrow
ID: 11943011
Should I install active x with my application, or just put out an error message to the user.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11943035
It is against Micro$oft's license agreement to install it if they don't have the application installed.  Therefore, you should put up an error message.

Bob
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
To export Lotus Notes to Outlook PST or Exchange and Domino Server files to Exchange Server or PST files with ease, go for Kernel for Lotus Notes to Outlook conversion tool. Through the video, you can watch the conversion process. A common user with…
Watch the video to know the process of migration of Exchange or Office 365 mailboxes in absence of MS Outlook. It is an eminent tool which can easily migrate Public, Archive user mailboxes from one another Exchange server and Office 365. Kernel Migr…

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question