Solved

Associated program

Posted on 2002-05-28
5
181 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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