Tuncay wrote:
jballi, you still have not a topic on scripts and functions forum for this?!

But hey, I made a link on top of this topic, so people should find yours more easily.

Its definitiv the better solution.
Sorry to bump this old post but
I just knew that there had to be a better solution out there than my makeshift function and somehow I stumbled on to it. I just wish that someone had pointed this out to me sooner.
TheGood wrote a function to find the associated program to any file extension using the built-in
AssocQueryStringW function. The original solution can be found here:
My version of the function (I named it
AssociatedProgram) should work on AHK and AHK_L.
Code:
;-- Function: AssociatedProgram
;-- Description: Returns the full path of the program (if any) associated to
; a file extension (p_FileExt).
;-- Original author: TheGood
; http://www.autohotkey.com/forum/viewtopic.php?p=363558#363558
;-- Programming note: AssocQueryStringA is never called because it returns
; invalid results on Windows XP.
AssociatedProgram(p_FileExt)
{
Static ASSOCSTR_EXECUTABLE:=2
;-- Workaround for AutoHotkey Basic
PtrType:=A_PtrSize ? "Ptr":"UInt"
;-- File extension
if SubStr(p_FileExt,1,1)<>"."
p_FileExt:="." . p_FileExt ;-- Prepend dot
;-- If needed, convert file extension to Unicode
l_FileExtW:=p_FileExt
if not A_IsUnicode
{
nSize:=StrLen(p_FileExt)+1 ;-- Size in chars including terminating null
VarSetCapacity(l_FileExtW,nSize*2) ;-- Size in bytes
DllCall("MultiByteToWideChar","UInt",0,"UInt",0,PtrType,&p_FileExt,"Int",-1,PtrType,&l_FileExtW,"Int",nSize)
}
;-- Get the full path to the program
VarSetCapacity(l_EXENameW,65536,0) ;-- Size allows for 32K characters
DllCall("shlwapi.dll\AssocQueryStringW"
,"UInt",0 ;-- ASSOCF flags
,"UInt",ASSOCSTR_EXECUTABLE ;-- ASSOCSTR flags
,PtrType,&l_FileExtW ;-- pszAssoc (file extension used)
,PtrType,0 ;-- pszExtra (not used)
,PtrType,&l_EXENameW ;-- pszOut (output string)
,PtrType . "*",65536) ;-- pcchOut (len of the output string)
;-- If needed, convert result back to ANSI
if A_IsUnicode
Return l_EXENameW
else
{
nSize:=DllCall("WideCharToMultiByte","UInt",0,"UInt",0,PtrType,&l_EXENameW,"Int",-1,PtrType,0,"Int",0,PtrType,0,PtrType,0)
;-- Returns the number of bytes including the terminating null
VarSetCapacity(l_EXEName,nSize)
DllCall("WideCharToMultiByte","UInt",0,"UInt",0,PtrType,&l_EXENameW,"Int",-1,PtrType,&l_EXEName,"Int",nSize,PtrType,0,PtrType,0)
Return l_EXEName
}
}
Example of use:
Code:
#NoEnv
#SingleInstance Force
ExtList=
(ltrim join|
7z
ahk
avi
bmp
cab
chm
css
csv
doc
fon
gif
htm
ini
jar
jpg
js
log
m3u
m4a
mid
mov
mp3
mp4
mpa
mpg
msg
pdf
pls
png
pps
ppt
ra
rar
rtf
tif
torrent
txt
url
vbs
wav
wma
wmv
wsf
xls
xml
zip
)
Loop Parse,ExtList,|
RPList.=A_LoopField . "`t" . AssociatedProgram(A_LoopField) . "`n"
MsgBox %RPList%
return
#include AssociatedProgram.ahk
To find the default web browser, call the function using the "htm", "html", or whatever file extension you think is best.
All credit and thanks to
TheGood and the others that contributed to this solution. Read the entire discussion thread
here for additional information on this topic.
Edit 20111216_2243: This function is not 64-bit ready.
Edit 20111217_0057: OK, the function should be 64-bit ready but it has not been tested on a 64-bit build. Let me know if you have a problem.