PC Review


Reply
Thread Tools Rate Thread

Determining default mail client

 
 
at
Guest
Posts: n/a
 
      14th Oct 2010
Hello,

One of my Access applications is used by many users, with all kind of
systems and Windows versions. In this application, I have a function to
determine to standard mail client:

StrMailClient = fReturnRegKeyValue(HKEY_LOCAL_MACHINE,
"Software\clients\mail", "")

Function fReturnRegKeyValue(ByVal lngKeyToGet As Long, ByVal strKeyName
As String, ByVal strValueName As String) as String
'This code was originally written by Terry Kreft and Dev Ashish.
Dim lnghKey As Long
Dim strClassName As String
Dim lngClassLen As Long
Dim lngReserved As Long
Dim lngSubKeys As Long
Dim lngMaxSubKeyLen As Long
Dim lngMaxClassLen As Long
Dim lngValues As Long
Dim lngMaxValueNameLen As Long
Dim lngMaxValueLen As Long
Dim lngSecurity As Long
Dim ftLastWrite As FILETIME
Dim lngtype As Long
Dim lngData As Long
Dim lngTmp As Long
Dim strRet As String
Dim varRet As Variant
Dim lngRet As Long

On Error GoTo fReturnRegKeyValue_Err

'Open the key first
lngTmp = apiRegOpenKeyEx(lngKeyToGet, strKeyName, 0&, KEY_READ,
lnghKey)

'Are we ok?
If Not (lngTmp = ERROR_SUCCESS) Then Err.Raise lngTmp + vbObjectError

lngReserved = 0&
strClassName = String$(MAXLEN, 0): lngClassLen = MAXLEN

'Get boundary values
lngTmp = apiRegQueryInfoKey(lnghKey, strClassName, _
lngClassLen, lngReserved, lngSubKeys, lngMaxSubKeyLen, _
lngMaxClassLen, lngValues, lngMaxValueNameLen, _
lngMaxValueLen, lngSecurity, ftLastWrite)

'How we doin?
If Not (lngTmp = ERROR_SUCCESS) Then Err.Raise lngTmp + vbObjectError

'Now grab the value for the key
strRet = String$(MAXLEN - 1, 0)
lngTmp = apiRegQueryValueEx(lnghKey, strValueName, lngReserved,
lngtype, ByVal strRet, lngData)
Select Case lngtype
Case REG_SZ
lngTmp = apiRegQueryValueEx(lnghKey, strValueName, lngReserved,
lngtype, ByVal strRet, lngData)
varRet = Left(strRet, lngData - 1)
Case REG_DWORD
lngTmp = apiRegQueryValueEx(lnghKey, strValueName, lngReserved,
lngtype, lngRet, lngData)
varRet = lngRet
Case REG_BINARY
lngTmp = apiRegQueryValueEx(lnghKey, strValueName, lngReserved,
lngtype, ByVal strRet, lngData)
varRet = Left(strRet, lngData)
Case REG_EXPAND_SZ
lngTmp = apiRegQueryValueEx(lnghKey, strValueName, lngReserved,
lngtype, ByVal strRet, lngData)
varRet = Left(strRet, lngData - 1)
End Select

'All quiet on the western front?
If Not (lngTmp = ERROR_SUCCESS) Then Err.Raise lngTmp + vbObjectError

fReturnRegKeyValue_Exit:
fReturnRegKeyValue = varRet
lngTmp = apiRegCloseKey(lnghKey)
Exit Function
fReturnRegKeyValue_Err:
varRet = "Error: Key or Value Not Found."
Resume fReturnRegKeyValue_Exit
End Function
(for reasons for readability, I omitted the declaration of constants and
some aditional functions)

When this function is used on a computer with *Windows XP*, the result
is OK.
However, when I use this same function on a computer with *Windows Vista
*or* Windows 7*, the result is not OK. I figured out that the outcome is
not the value of the key above, but from another key:
"hkey_local_machine\software\wow6432node\clients\mail".

I already tried to adapt the function: StrMailClient =
fReturnRegKeyValue(HKEY_CURRENT_USER, "Software\clients\mail\", "")
This works fine for Windows Vista and Windows 7, but with Windows XP it
does not work (key does not exist).

So my question is: is there any way, function or registry key which
gives the right default mail client, regardless the Windows version? Or
is there any decent possibility to determine the current Windows
version, which can be used to use either registry retrieval function?
I must say that my knowledge of registry and 32/64 bit topics is very
limited.

Thanks for any suggestions,

Paul

 
Reply With Quote
 
 
 
 
a a r o n . k e m p f @ g m a i l . c o m
Guest
Posts: n/a
 
      15th Oct 2010
uh.. Docmd.SendObject should launch the default mail client, right?






On Oct 14, 2:26*pm, at <"paul(at)kpnmail.nl"> wrote:
> * Hello,
>
> One of my Access applications is used by many users, with all kind of
> systems and Windows versions. In this application, I have a function to
> determine to standard mail client:
>
> StrMailClient = fReturnRegKeyValue(HKEY_LOCAL_MACHINE,
> "Software\clients\mail", "")
>
> Function fReturnRegKeyValue(ByVal lngKeyToGet As Long, ByVal strKeyName
> As String, ByVal strValueName As String) as String
> * * *'This code was originally written by Terry Kreft and Dev Ashish.
> * * *Dim lnghKey As Long
> * * *Dim strClassName As String
> * * *Dim lngClassLen As Long
> * * *Dim lngReserved As Long
> * * *Dim lngSubKeys As Long
> * * *Dim lngMaxSubKeyLen As Long
> * * *Dim lngMaxClassLen As Long
> * * *Dim lngValues As Long
> * * *Dim lngMaxValueNameLen As Long
> * * *Dim lngMaxValueLen As Long
> * * *Dim lngSecurity As Long
> * * *Dim ftLastWrite As FILETIME
> * * *Dim lngtype As Long
> * * *Dim lngData As Long
> * * *Dim lngTmp As Long
> * * *Dim strRet As String
> * * *Dim varRet As Variant
> * * *Dim lngRet As Long
>
> * * *On Error GoTo fReturnRegKeyValue_Err
>
> * * *'Open the key first
> * * *lngTmp = apiRegOpenKeyEx(lngKeyToGet, strKeyName, 0&, KEY_READ,
> lnghKey)
>
> * * *'Are we ok?
> * * *If Not (lngTmp = ERROR_SUCCESS) Then Err.Raise lngTmp + vbObjectError
>
> * * *lngReserved = 0&
> * * *strClassName = String$(MAXLEN, 0): *lngClassLen = MAXLEN
>
> * * *'Get boundary values
> * * *lngTmp = apiRegQueryInfoKey(lnghKey, strClassName, _
> * * * * *lngClassLen, lngReserved, lngSubKeys, lngMaxSubKeyLen,_
> * * * * *lngMaxClassLen, lngValues, lngMaxValueNameLen, _
> * * * * *lngMaxValueLen, lngSecurity, ftLastWrite)
>
> * * *'How we doin?
> * * *If Not (lngTmp = ERROR_SUCCESS) Then Err.Raise lngTmp + vbObjectError
>
> * * *'Now grab the value for the key
> * * *strRet = String$(MAXLEN - 1, 0)
> * * *lngTmp = apiRegQueryValueEx(lnghKey, strValueName, lngReserved,
> lngtype, ByVal strRet, lngData)
> * * *Select Case lngtype
> * * * *Case REG_SZ
> * * * * *lngTmp = apiRegQueryValueEx(lnghKey, strValueName, lngReserved,
> lngtype, ByVal strRet, lngData)
> * * * * *varRet = Left(strRet, lngData - 1)
> * * * *Case REG_DWORD
> * * * * *lngTmp = apiRegQueryValueEx(lnghKey, strValueName, lngReserved,
> lngtype, lngRet, lngData)
> * * * * *varRet = lngRet
> * * * *Case REG_BINARY
> * * * * *lngTmp = apiRegQueryValueEx(lnghKey, strValueName, lngReserved,
> lngtype, ByVal strRet, lngData)
> * * * * *varRet = Left(strRet, lngData)
> * * * *Case REG_EXPAND_SZ
> * * * * *lngTmp = apiRegQueryValueEx(lnghKey, strValueName, lngReserved,
> lngtype, ByVal strRet, lngData)
> * * * * *varRet = Left(strRet, lngData - 1)
> * * *End Select
>
> * * *'All quiet on the western front?
> * * *If Not (lngTmp = ERROR_SUCCESS) Then Err.Raise lngTmp + vbObjectError
>
> fReturnRegKeyValue_Exit:
> * * *fReturnRegKeyValue = varRet
> * * *lngTmp = apiRegCloseKey(lnghKey)
> * * *Exit Function
> fReturnRegKeyValue_Err:
> * * *varRet = "Error: Key or Value Not Found."
> * * *Resume fReturnRegKeyValue_Exit
> End Function
> (for reasons for readability, I omitted the declaration of constants and
> some aditional functions)
>
> When this function is used on a computer with *Windows XP*, the result
> is OK.
> However, when I use this same function on a computer with *Windows Vista
> *or* Windows 7*, the result is not OK. I figured out that the outcome is
> not the value of the key above, but from another key:
> "hkey_local_machine\software\wow6432node\clients\mail".
>
> I already tried to adapt the function: StrMailClient =
> fReturnRegKeyValue(HKEY_CURRENT_USER, "Software\clients\mail\", "")
> This works fine for Windows Vista and Windows 7, but with Windows XP it
> does not work (key does not exist).
>
> So my question is: is there any way, function or registry key which
> gives the right default mail client, regardless the Windows version? Or
> is there any decent possibility to determine the current Windows
> version, which can be used to use either registry retrieval function?
> I must say that my knowledge of registry and 32/64 bit topics is very
> limited.
>
> Thanks for any suggestions,
>
> Paul


 
Reply With Quote
 
Paul Bergers
Guest
Posts: n/a
 
      15th Oct 2010
Hi Arvin,

Thank you very much for your suggestion. It sounds logical to me, I will
build this in.

Paul

Op 15-10-10 20:23, Arvin Meyer schreef:
> Hi Paul,
>
> I don't think that you're going to get what you want by using that code. I
> suggest using the following code to determine which version of Windows, then
> branch accordingly to use something else if the version is later than XP. I
> haven't tested this yet on Windows 7, but it should work:
>
> Option Compare Database
> Option Explicit
> ' Arvin Meyer 2/17/2010
>
> Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation
> As OSVERSIONINFO) As Integer
>
> Public Type OSVERSIONINFO
> lngOSVersionInfoSize As Long
> lngMajorVersion As Long
> lngMinorVersion As Long
> lngBuildNumber As Long
> lngPlatformId As Long
> strCSDVersion As String * 128
> End Type
>
> Public Function GetVersion() As String
> Dim verInfo As OSVERSIONINFO
> Dim intValue As Integer
>
> verInfo.lngOSVersionInfoSize = 148
> verInfo.strCSDVersion = Space$(128)
> intValue = GetVersionExA(verInfo)
> With verInfo
> Select Case .lngPlatformId
>
> Case 1
> Select Case .lngMinorVersion
> Case 0
> GetVersion = "Windows 95"
> Case 10
> GetVersion = "Windows 98"
> Case 90
> GetVersion = "Windows Millennium"
> End Select
>
> Case 2
> Select Case .lngMajorVersion
> Case 3
> GetVersion = "Windows NT 3.51"
> Case 4
> GetVersion = "Windows NT 4.0"
> Case 5
> Select Case .lngMinorVersion
> Case 0
> GetVersion = "Windows 2000"
> Case 1
> GetVersion = "Windows XP"
> Case 2
> GetVersion = "Windows Server 2003"
> End Select
> Case 6
> GetVersion = "Windows Vista"
> Case 7
> GetVersion = "Windows 7"
> End Select
> Case Else
> GetVersion = "Unknown Windows"
> End Select
> End With
> End Function
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create an email in a client's default mail client Sue L. Microsoft Access VBA Modules 3 1st Apr 2010 10:27 PM
"EITHER THERE IS NO DEFAULT MAIL CLIENT OR THE CURRENT MAIL CLIENT CANNOT FULFILL THE MESSAGING REQUEST. PLEASE RUN MICROSOFT OUTLOOK AND SET IT AS THE DEFAULT MAIL CLIENT" Jon D. Schoenherz Microsoft Outlook Discussion 7 21st Mar 2009 05:43 AM
Re: Third party email client as default mail client Still learning Windows XP General 1 7th Jul 2008 02:28 PM
Determining Current User's Default E-Mail Account =?Utf-8?B?SmFzb24gS2FsbGVsaXM=?= Microsoft Outlook VBA Programming 4 16th Jun 2005 06:39 PM
RE: Either there is no default mail client or the current mail client. =?Utf-8?B?TGVwcG1peA==?= Microsoft Outlook Discussion 0 3rd May 2005 08:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:52 AM.