Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / December 2007



Tip: Looking for answers? Try searching our database.

Query shell-verbs and associations

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alexander Mueller - 04 Dec 2007 00:39 GMT
Hi

I have some questions concerning ShellExecute(Ex)

- How can I enum / check the verbs that are supported for a given
file-extension? In detail i want to call the "edit" verb for
many filetypes. If there is no "edit" i want to call "open".
How do I know if the verb "edit" is supported?
Is there a more handy set of functions then RegQueryValue and RegEnumKeys?

- What again is the API for getting the application (the exefile-path)
associated to the verb of a certain file-extension.
In recall it starts with or contains "Assoc".

MfG,
Alex
mayayana - 04 Dec 2007 04:50 GMT
> I have some questions concerning ShellExecute(Ex)
>
[quoted text clipped - 3 lines]
> How do I know if the verb "edit" is supported?
> Is there a more handy set of functions then RegQueryValue and RegEnumKeys?

 I don't know whether this is really any easier
than checking the Registry, but I think it will
work. It uses the Shell object. My sample code
is a quick, late-bound script version, but it can be
done with a reference to Microsoft Shell Controls
and Automation rather than using CreateObject:

--------------------

Dim SHAp, oFol, oFolItem, FIVerbs, oVerb, s1, i2
Set SHAp = CreateObject("Shell.Application")
 Set oFol = SHAp.NameSpace("C:\")
 Set oFolItem = oFol.ParseName("icon1.gif")
 Set FIVerbs = oFolItem.Verbs
    For i2 = 0 to FIVerbs.count - 1
       Set oVerb = FIVerbs.Item(i2)
       s1 = s1 & oVerb.Name & vbCrLf
     Next
   MsgBox s1

Set FIVerbs = Nothing '-- FolderItemVerbs object.
Set oFolItem = Nothing '-- FolderItem object.
Set oFol = Nothing  '-- Shell folder object.
Set SHAp = Nothing
----------------------

I *think* that works if run as a VBS. I'm onWin98
right now, where the Verb object doesn't seem to
be valid, so I can't test it. But I think it works
on 2000/ME/XP.
Alexander Mueller - 05 Dec 2007 13:53 GMT
mayayana schrieb:
>> I have some questions concerning ShellExecute(Ex)
>>
[quoted text clipped - 10 lines]
> done with a reference to Microsoft Shell Controls
> and Automation rather than using CreateObject:

Hi mayayana

thanks for your suggestion. Unfortunately I shall
not use another COM-object. Some users still have NT4
where afaik Shell-automation isn't supported (
unless you a special IE-ver is installed) .

Also afaik the Verb-Names include ampersands and
are afaics also localized ("edit" becomes
"&Bearbeiten"  for instance).

Thanks anyhow. I thought Shell-automation is a lightweight wrapper
around Shell-API. Unfortunaetly i couldn't find
an interface of function that corresponds to
FolderItemVerbs.

MfG,
Alex

> --------------------
>
[quoted text clipped - 19 lines]
> be valid, so I can't test it. But I think it works
> on 2000/ME/XP.
mayayana - 05 Dec 2007 14:44 GMT
> Also afaik the Verb-Names include ampersands and
> are afaics also localized ("edit" becomes
[quoted text clipped - 4 lines]
> an interface of function that corresponds to
> FolderItemVerbs.

  It's there in the Shell library. In Win9x, and I
think 2000, that's shdoc401.dll. In WinXP the
whole Shell object/Web View thing has been
mostly removed and is emulated from shell32.dll.

 You do have many good reasons not to go that
route, though. :) You'd need Active Desktop installed
on NT and it would take some cleanup of the strings.

 If it were me I think I'd just go to the source in the
Registry. (That's where the API gets its info., after all.)
   For instance, HKCR\.txt points to HKCR\txtfile,
which has a subkey named shell, which has subkeys
to correspond to whatever's on the context menu above
the first line (with shell extensions below that). The command
key under each of those keys has the EXE path. You'd
have to also go to HKCR\* to get all the items on the
top menu section, but it sounds like that's not relevant
to your purposes, anyway.
Donald Lessau - 04 Dec 2007 06:36 GMT
> - What again is the API for getting the application (the exefile-path)
> associated to the verb of a certain file-extension.
> In recall it starts with or contains "Assoc".

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

Don
Alexander Mueller - 05 Dec 2007 14:00 GMT
Donald Lessau schrieb:

>> - What again is the API for getting the application (the exefile-path)
>> associated to the verb of a certain file-extension.
[quoted text clipped - 7 lines]
>
> Don

Hi Don

the prob is that FindExecutable returns the exefile associated with the
"open" verb, which is likely the same as for "edit" in 90%
of all occurrences, but not certainly. For example
*.png is asociated to ACDSee on my system, whereas "edit" launches
Paint.

Thx anyhow.

MfG,
Alex
Alexander Mueller - 05 Dec 2007 14:09 GMT
Alexander Mueller schrieb:
> Donald Lessau schrieb:

>>> - What again is the API for getting the application (the exefile-path)
>>> associated to the verb of a certain file-extension.
>>> In recall it starts with or contains "Assoc".

>> Private Declare Function FindExecutable _
>>    Lib "shell32.dll" Alias "FindExecutableA" ( _
[quoted text clipped - 5 lines]
> "open" verb, which is likely the same as for "edit" in 90%
> of all occurrences, but not certainly.

Nonetheless that points to the right direction!
The remarks refer to AssocQueryString, where the shell-verb
can be specified by the pszExtra-param.
Which is also a solution for verifying whether "edit" is supported
as verb in ShellExecuteEx.

Thanks,
Alex
Donald Lessau - 05 Dec 2007 19:24 GMT
> Alexander Mueller schrieb:
>> Donald Lessau schrieb:
[quoted text clipped - 18 lines]
> Which is also a solution for verifying whether "edit" is supported
> as verb in ShellExecuteEx.

Ah, interesting. Please let me know if it works out.

Don
Alexander Mueller - 06 Dec 2007 13:40 GMT
Donald Lessau schrieb:

>>>>> - What again is the API for getting the application (the exefile-path)
>>>>> associated to the verb of a certain file-extension.
>>>>> In recall it starts with or contains "Assoc".
>>
>>>> Private Declare Function FindExecutable _

>> Nonetheless that points to the right direction!
>> The remarks refer to AssocQueryString, where the shell-verb
[quoted text clipped - 3 lines]
>>
> Ah, interesting. Please let me know if it works out.

Hi Don,

Yes it does, here's the code:

Call it like:

  Dim strExe$

  If IsVerbSupported("edit", ".bmp", strExe) Then
          MsgBox ".bmp is edited by """ & strExe & """"
  Else
     MsgBox ".bmp has not ""edit"" association"
  End If

MfG,
Alex

'-------------module-code

Option Explicit

Private Enum ASSOCF

    ASSOCF_INIT_NOREMAPCLSID = &H1
    ASSOCF_INIT_BYEXENAME = &H2
    ASSOCF_OPEN_BYEXENAME = &H2
    ASSOCF_INIT_DEFAULTTOSTAR = &H4
    ASSOCF_INIT_DEFAULTTOFOLDER = &H8
    ASSOCF_NOUSERSETTINGS = &H10
    ASSOCF_NOTRUNCATE = &H20
    ASSOCF_VERIFY = &H40
    ASSOCF_REMAPRUNDLL = &H80
    ASSOCF_NOFIXUPS = &H100
    ASSOCF_IGNOREBASECLASS = &H200

End Enum

Private Enum ASSOCSTR

    ASSOCSTR_COMMAND = 1
    ASSOCSTR_EXECUTABLE
    ASSOCSTR_FRIENDLYDOCNAME
    ASSOCSTR_FRIENDLYAPPNAME
    ASSOCSTR_NOOPEN
    ASSOCSTR_SHELLNEWVALUE
    ASSOCSTR_DDECOMMAND
    ASSOCSTR_DDEIFEXEC
    ASSOCSTR_DDEAPPLICATION
    ASSOCSTR_DDETOPIC
    ASSOCSTR_INFOTIP
    ASSOCSTR_QUICKTIP
    ASSOCSTR_TILEINFO
    ASSOCSTR_CONTENTTYPE
    ASSOCSTR_DEFAULTICON
    ASSOCSTR_SHELLEXTENSION

End Enum

Private Const MAX_PATH = 260
Private Const E_POINTER As Long = &H80004003
Private Const S_FALSE As Long = &H1
Private Const S_OK As Long = &H0

Private Declare Function wu32_AssocQueryString Lib "shlwapi.dll" Alias
"AssocQueryStringA" (ByVal Flags As ASSOCF, ByVal str As ASSOCSTR, ByVal
pszAssoc As String, ByVal pszExtra As String, ByVal pszOut As String,
ByRef pcchOut As Long) As Long

Public Function IsVerbSupported _
        ( _
            ByVal strVerb$, _
            ByVal strExtArg$, _
            Optional ByRef strExecutable$ _
        ) _
    As Boolean

    IsVerbSupported = GetAssocString _
        ( _
            ASSOCSTR_EXECUTABLE, _
            strExtArg, _
            strExecutable, _
            strVerb _
        )

End Function

Private Function GetAssocString _
    ( _
        flgASSOCSTR As ASSOCSTR, _
        strExtArg As String, _
        ByRef strOutString As String, _
        Optional strExtra As String = "open", _
        Optional flgASSOCF As ASSOCF = -1 _
    ) _
    As Boolean

Const FLAGS_DEFAULT As Long = _
    ASSOCF_INIT_DEFAULTTOFOLDER _
    Or ASSOCF_NOTRUNCATE _
    Or ASSOCF_VERIFY

Dim lngLenOutFile As Long
Dim strExtUsed As String
Dim p As Long

    If flgASSOCF = -1 Then
        flgASSOCF = FLAGS_DEFAULT
    End If

    strOutString = String$(MAX_PATH, 0)
    lngLenOutFile = Len(strOutString)

     p = InStrRev(strExtArg, ".")
    If p = 0 Then
        strExtUsed = "." & strExtArg
    Else
        strExtUsed = Mid$(strExtArg, p)
    End If

        Select Case wu32_AssocQueryString _
            ( _
                flgASSOCF, _
                flgASSOCSTR, _
                strExtUsed, _
                strExtra, _
                strOutString, _
                lngLenOutFile _
            )

        Case S_OK:

            p = InStr(1, strOutString, vbNullChar, vbBinaryCompare)
            If p > 0 Then
                strOutString = Left$(strOutString, p - 1)
            End If

            strOutString = Trim(strOutString)
            GetAssocString = True

        'The pszOut buffer is too small to hold the entire string.
        Case E_POINTER:
            GetAssocString = False

        'pszOut is NULL. pcchOut contains the required buffer size.
        Case S_FALSE:
            GetAssocString = False

         'Other error
        Case Else:
            GetAssocString = False

        End Select

End Function
Donald Lessau - 06 Dec 2007 19:01 GMT
> Donald Lessau schrieb:
>
[quoted text clipped - 17 lines]
> Yes it does, here's the code:
> ...

Thanks a lot!

Don
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.