Results 1 to 6 of 6

Thread: [RESOLVED] Find Default Mail Client?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Resolved [RESOLVED] Find Default Mail Client?

    Is there a way I can test to see what the default mail client is?

    Thanks

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Find Default Mail Client?

    There might be some other way of doing it, but the first thing that hit me was to read the default string from the following key in the registry:
    HKEY_CLASSES_ROOT\mailto\shell\open\command

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Find Default Mail Client?

    hmm not sure how to do that... any ideas?

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Find Default Mail Client?

    I guess this can't be done?

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Find Default Mail Client?

    VB Code:
    1. Private Declare Function RegCloseKey Lib "advapi32.dll" ( _
    2.     ByVal hKey As Long _
    3. ) As Long
    4.  
    5. Private Declare Function RegOpenKeyEx _
    6.  Lib "advapi32.dll" Alias "RegOpenKeyExA" ( _
    7.     ByVal hKey As Long, _
    8.     ByVal lpSubKey As String, _
    9.     ByVal ulOptions As Long, _
    10.     ByVal samDesired As Long, _
    11.     ByRef phkResult As Long _
    12. ) As Long
    13.  
    14. Private Declare Function RegQueryValueEx _
    15.  Lib "advapi32.dll" Alias "RegQueryValueExA" ( _
    16.     ByVal hKey As Long, _
    17.     ByVal lpValueName As String, _
    18.     ByVal lpReserved As Long, _
    19.     ByRef lpType As Long, _
    20.     ByRef lpData As Any, _
    21.     ByRef lpcbData As Long _
    22. ) As Long
    23.  
    24. Private Const HKEY_CLASSES_ROOT As Long = &H80000000
    25. Private Const REG_SZ As Long = 1
    26. Private Const KEY_QUERY_VALUE = &H1
    27. Private Const KEY_SET_VALUE = &H2
    28. Private Const KEY_CREATE_SUB_KEY = &H4
    29. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
    30. Private Const KEY_NOTIFY = &H10
    31. Private Const KEY_CREATE_LINK = &H20
    32. Private Const STANDARD_RIGHTS_ALL = &H1F0000
    33. Private Const SYNCHRONIZE = &H100000
    34. Private Const ERROR_SUCCESS As Long = 0&
    35. Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _
    36.     KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS _
    37.     Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
    38.    
    39. Public Function DefaultMail() As String
    40.     Dim hKey As Long
    41.     Dim sRetVal As String
    42.     Const MAX_PATH = 260&
    43.     If RegOpenKeyEx(HKEY_CLASSES_ROOT, "\mailto\shell\open\command\", _
    44.      0, KEY_ALL_ACCESS, hKey) = ERROR_SUCCESS Then
    45.         sRetVal = String(MAX_PATH + 1, vbNullChar)
    46.         If RegQueryValueEx(hKey, vbNullString, 0&, REG_SZ, _
    47.          ByVal sRetVal, MAX_PATH + 1) = ERROR_SUCCESS Then
    48.             DefaultMail = Left$(sRetVal, InStr(sRetVal, vbNullChar) - 1)
    49.         End If
    50.         Call RegCloseKey(hKey)
    51.     End If
    52. End Function
    You have to parse the return value of the DefaultMail function since it will return the path to the mail client including information on how to open it to mail someone... Just run it and you'll see what you need to do.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Find Default Mail Client?

    Awesome, just need to figure out a good way to deal with the string. thanks alot for the help.

Posting Permissions

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



Click Here to Expand Forum to Full Width