Solved

Associated program

Posted on 2002-05-28
5
182 Views
Last Modified: 2010-05-02
I need a quick and easy way of finding the program associated with a file extension.

First to see will take.
0
Comment
Question by:Belazir
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7039075
could you elaborate on this!
0
 

Author Comment

by:Belazir
ID: 7039090
As in, a bit of code to find out what is registered as being the program associated with any file extension.  For example, I am iterating through a list of files, some of which might be .jpg, some of which might be .gif, some of which might be .doc, and some of which might be .ras.  How do I find out what is the program registered on the user's computer as being associated with each extension?
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 147 total points
ID: 7039105
Ok, this example demonstrates how to find the executable associated with a specific file. The file must exist for this to work:

Const MAX_FILENAME_LEN = 260
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Private Sub Form_Load()
    'KPD-Team 1999
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
   Dim i As Integer, s2 As String
   Const sFile = "C:\Windows\Readme.txt"

   'Check if the file exists
   If Dir(sFile) = "" Or sFile = "" Then
        MsgBox "File not found!", vbCritical
        Exit Sub
   End If
   'Create a buffer
   s2 = String(MAX_FILENAME_LEN, 32)
   'Retrieve the name and handle of the executable, associated with this file
   i = FindExecutable(sFile, vbNullString, s2)
   If i > 32 Then
      MsgBox Left$(s2, InStr(s2, Chr$(0)) - 1)
   Else
      MsgBox "No association found !"
   End If
End Sub

0
 

Author Comment

by:Belazir
ID: 7039123
that will do nicely

a very profitable five minutes for you, there...
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7039153
Two out of two cannot be bad indeed. Happy to have helped.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

832 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