-
September 9th, 2004, 06:52 PM
#1
Retrieve file associations
Hi all,
Without jumping through hoops, is there an easy way to retrieve (programmatically) what executable will be run for any given file extension? I've found many ways to create an association, and clever ways to retrieve the *name* of the program that will be run, but seemingly no way to find the path, and name of the executable!
Suppose I want to find out what *file* runs an MDB database.
Because my clients have at least three different versions of Office, the exe path for MSAccess can be in at least three different locations!
(Oh, and I can't use ShellExecute, because of "/" switches at the end...)
All I need is what is the current default program name and path for MDB files!
Any help appreciated,
Mark
-
September 10th, 2004, 12:45 AM
#2
Re: Retrieve file associations
try using:
FindExecutable
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, _
ByVal lpResult As String) As Long
check out the details in MSDN. Also be sure to validate the return value in lpResult , it may not be what you expect.
my code looks like this:
Dim FindExe As String
Dim FindRtn As Long
FindExe = Space$(255) ' buffer for executable
' strCFIL is usually a .doc or .xls
FindRtn = FindExecutable(strCFIL, "c:\", FindExe)' check the return code
If FindRtn > 32 Then ' got the association
'... shell() or something...
End If
last, for those pesky "/" characters, try inserting them in strings using Chr(47)
Cheers,
Doug.
-
September 12th, 2004, 07:04 PM
#3
Re: Retrieve file associations
Thanks for that!
What I've tried (and ended up using) is this:-
Retrieve from the registry the the (default) entry for
HKLM\Software\Classes\.MDB files
It will return "Microsoft.Access.11" (in my case).
Now go to HKLM\Software\Classes\Access.Application.11\Shell\Open\Command
It'll return the path to the exe along with switches.
I used some code to remove all characters including and after the first "/" switch,
and you have the path to the default program that runs the association!
I'll try this way - see what happens. Thanks for your repsonse though - I've printed it out for future reference!
Mark
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|