Results 1 to 10 of 10
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Associated Application (Win API)

    Does anyone know the API call (or other method) for obtaining the name of the program to which a file type is associated? I'm searching with no luck so far.

    If I have WinZip installed, for example, I want to be able to pass a file named "foobar.zip" to a function and have it return "winzip.exe" -- derived from the OS.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Associated Application (Win API)

    How about <pre>Private Declare Function FindExecutable Lib "shell32.dll" _
    Alias "FindExecutableA" _
    (ByVal lpFile As String, _
    ByVal lpDirectory As String, _
    ByVal sResult As String) As Long</pre>


    An example of it's use can be had at <A target="_blank" HREF=http://www.allapi.net/apilist/example.php?example=FindExecutable>AllAPI Network</A>.

    Works fine on a zip file, returning winzip32.exe to me.

    Andrew C

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Associated Application (Win API)

    Andrew does it again! You are dialed in, man.

    Thanks.

    p.s. I was camped in the AllAPI API Guide for an hour looking for that thing. I tried all kinds of searches but found nothing. I knew it was in there.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Associated Application (Win API)

    Kevin,

    I suppose you know this, but there is the ShellExecute API, which will launch the exe of a file passed to it, if such file as a registered association. Sample code : <pre>Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

    Sub ShellExec(strFileName As String)
    Dim Ret As Long
    Ret = ShellExecute(GetDesktopWindow(), _
    "Open", strFileName, "", "C:", 1)
    If Ret <= 32 Then
    MsgBox "Error opening File" & _
    vbCrLf & vbCrLf & "ERROR : " & _
    Ret, vbCritical
    End If
    End Sub</pre>

    Use ShellExec(

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Associated Application (Win API)

    Yes, and it returns a pretty robust set of error codes. The one that would be of use to me is SE_ERR_NOASSOC (&H1F or 31 Long).

    But I needed to test for the file association before calling the SHShellExecute funtion.

    What I've got now is a Word Open dialog that will let the user open a .pdf, .jpg or whathaveyou from Word. I'm also developing this idea into a way to better use automation, but that's for another post.

    Thanks again for your help.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Associated Application (Win API)

    Andrew, et.al.,

    Would you mind taking a look at <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/Q140/7/24.asp>this article</A>?

    The gist is FindExecutate fails on paths of LFNs that have spaces. "This is by design." -- comforting isn't it.

    The workaround in the article has me confused. I can't get it to work.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Associated Application (Win API)

    Kevin,

    It only appears in certain circumstances, I think dependant on how path was stored in the Registry. On passing a word (doc) file to it it returned :<pre>C:Program FilesMicrosoft Office2000OfficeWINWORD.EXE</pre>

    which contains spaces. Have you an example of an application where it does not function. It could be possible that Office 97 is causing the problem, or at least the way registry entries are stored. See if you can find any non Office apps that cause the problem.

    Andrew

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Associated Application (Win API)

    Try SomeExcelTemplate.xlt as your filename. What do you get?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  9. #9
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Associated Application (Win API)

    Hmm, I get C:Program FilesMicrosoft Office2000OfficeEXCEL.EXE, on a few I tried. I wonder if it is Office97 associations that cause the problem. I tried in XL97 VBA, but of course having Office 2000 installed means the file associations are not for 97.

    I'll keep digging but it will have to be tomorrow.

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Associated Application (Win API)

    Andrew,

    Hold off. I think I found the problem and there's nothing I can do about it. The article referred to the quotes around the registry path value. They were missing in my registry.

    If my users have the quotes missing I'm sunk. But by opening the file types tab and adding the quotes, findexecutable worked.

    Interestingly, I first added the quotes directly to several reg entries and it did not work. The File Types tab must hit all the relevant entries.

    Thanks for your help.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •