Solved

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

Posted on 2004-08-30
8
151 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 85

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 125 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 85

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 …
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now