IApplicationAssociationRegistration::QueryCurrentDefault Method

Determines the default application for a given association type. This is the default application launched by ShellExecute for that type.

Syntax

HRESULT QueryCurrentDefault(      
    LPCWSTR pszQuery,     ASSOCIATIONTYPE atQueryType,     ASSOCIATIONLEVEL alQueryLevel,     LPWSTR *ppszAssociation );

Parameters

pszQuery
[in] A pointer to a null-terminated, Unicode string that contains the file extension or protocol, such as .mp3 or http.
atQueryType
[in] One of the ASSOCIATIONTYPE enumeration values that specifies the type of association, such as extension or MIME type.
alQueryLevel
[in] One of the ASSOCIATIONLEVEL enumeration values that specifies the level of association, such as per-user or machine. This is typically AL_EFFECTIVE.
ppszAssociation
[out] When this method returns, contains the address of a pointer to the ProgID that identifies the current default association.
Note  It is the responsibility of the calling application to release the string through CoTaskMemFree.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

The string produced is typically a ProgID matching one of the ProgIDs associated with a registered application, but there are a few exceptions: If the string returned is a machine default protocol, it is a legacy string indicating a command line to a .exe handler instead of a ProgID. Similarly, if returning a machine default MIME type, it returns a legacy class identifier (CLSID) string instead of a ProgID.

See Also

Default Programs
Tags :


Community Content

David M. Kean - MSFT
Common HRESULTS
Returns E_INVALIDARG (0x80070057) when:

atQueryType is AT_URLPROTOCOL or AT_FILEEXTENSION and pszQuery is an empty string ("").
atQueryType is AT_FILEEXTENSION and pszQuery does not start with a period (.).

Returns HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) (0x80070483) when:

no application is associated with the file extension, mime type or protocol contained in pszQuery.

Returns HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) (0x8007007A) when:

atQueryType is AT_URLPROTOCOL and pszQuery is greater than 197 characters.
atQueryType is AT_FILEEXTENSION and pszQuery is greater than 242 characters.
atQueryType is AT_MIMETYPE and pszQuery is greater than 185 characters.

Otherwise, returns S_OK (0).
Tags : contentbug

Chris_Guzak
need to load the users hive before calling (Does not honour impersonation)
COM and Win32 impersonation do not load the registry hive of the user that this data relates to, thus impersonating or using CLSCTX_ENABLE_CLOAKING is not sufficient to use this API on a users behalf.

when calling from a service you need to load the user hive of the user you are targeting to use this API.
Tags :

Chris_Guzak
SHCreateAssociationRegistration creates the system provided implemenation of this interface
documented here:
http://msdn.microsoft.com/en-us/library/bb762125(VS.85).aspx
Tags :

Page view tracker