Solved

Associated program

Posted on 2002-05-28
5
179 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 Trending Threat Insights Every Day

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.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 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