• Welcome to Theos PowerBasic Museum 2017.

TIP - Find application associated to specific file extension

Started by Patrice Terrier, July 27, 2010, 02:54:10 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

' Find the application associated to a specific file extension.
%MAX_PATH                 = 260
%ASSOCSTR_EXECUTABLE      = 2    ' //  the executable part of command string
DECLARE FUNCTION AssocQueryString LIB "SHLWAPI.DLL" ALIAS "AssocQueryStringA" ( _
   BYVAL flags AS LONG _                                ' __in ASSOCF flags
, BYVAL str AS LONG _                                  ' __in ASSOCSTR str
, BYREF pszAssoc AS ASCIIZ _                           ' __in LPCSTR pszAssoc
, BYREF pszExtra AS ASCIIZ _                           ' __in LPCSTR pszExtra
, BYREF pszOut AS ASCIIZ _                             ' __out LPSTR pszOut
, BYREF pcchOut AS DWORD _                             ' __inout DWORD *pcchOut
) AS LONG                                              ' HRESULT

FUNCTION PBMAIN
    LOCAL szApplicationPath AS ASCIIZ * %MAX_PATH
    LOCAL sAssoc AS STRING
    LOCAL hr, flags AS LONG
    LOCAL dwSize AS DWORD

    sAssoc = ".mp3" + $NUL
    dwSize = SIZEOF(szApplicationPath)
    IF AssocQueryString(flags, _
                        %ASSOCSTR_EXECUTABLE, _
                        BYVAL STRPTR(sAssoc), _
                        "open", _
                        szApplicationPath, _
                        dwSize) = 0 THEN
     
       MsgBox LEFT$(szApplicationPath, dwSize) + $CR + $CR + "is the application associated to " + sAssoc

    END IF                                 

END FUNCTION
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com