Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find out the default application used to open a file type? 1

Status
Not open for further replies.

Crowley16

Technical User
Jan 21, 2004
6,931
GB
this is a bit of a pet project, which scans a hdd/folder and logs all files and folders in the hdd/folder.

I was wondering if there was a way to extract the default application needed to open up a file, so I can essentially open up files directly from a button...

Thanks

--------------------
Procrastinate Now!
 
Do you need to know the application, or can you let the program handle it?
Code:
SomeLink = "C:\Doc1.doc"
FollowHyperlink SomeLink
 
Is this still an issue Crowley16?

If so, I just found the FindExecutable function, which seems to do what you wish.

In the declaration section, try something like this

[tt]Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long

Const MAX_FILENAME_LEN = 260

' then some sub

Private Sub TestFindExecutable()

dim strFile as string
dim strResult as string
dim lngResult as long

strFile = "c:\mydir\myfile.xls" ' <- valid file
strResult = String(MAX_FILENAME_LEN, 32)
lngResult = FindExecutableA(strFile, vbNullString, strResult)

if lngResult > 32 then
msgbox left$(strResult, InStr(strResult, chr$(0))-1)
else
msgbox "no association found"
end if
End Sub[/tt]

You should be able to find more info on the function through search, here's one page Determining the Executable Associated with a Specific File. Another function that should perhaps work, is the AssocQueryString API function.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top