email client name re-visited

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

An old thread re-visited......... (I have a new twist
on an old problem)

Does anyone know how to obtain the name of the
current user's e-mail client? E.g., "Outlook",
"Outlook Express", etc..

Thanks,
Bill
 
The value I'm looking for is in the Windows Registry.
I've never used the GetSetting function nor do I know
that it is that function that is used to read a value from
the Registry.

I need to read the default value of:
HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail

Anyone know how to read values from the Registry?

Thanks,
Bill
 
Hi Bill,

I think you'll need to use the RegEnumValue() API function (and one or
two others). There's a VB example, easily modified for VBA, in the API
Guide downloadable from www.allapi.net.
 
Create reference to "Windows Script Host Object Model"

================================
Sub TestRegistryFunctions()

Dim sh As New WshShell

Key = "HKEY_CURRENT_USER\"
sh.RegWrite Key & "WSHTest\", "testkeydefault"
sh.RegWrite Key & "WSHTest\string1", "testkeystring1"
sh.RegWrite Key & "WSHTest\string2", "testkeystring2", "REG_SZ"
sh.RegWrite Key & "WSHTest\string3", "testkeystring3", "REG_EXPAND_SZ"
sh.RegWrite Key & "WSHTest\int", 123, "REG_DWORD"
Debug.Print sh.RegRead(Key & "WSHTest\")
Debug.Print sh.RegRead(Key & "WSHTest\string1")
Debug.Print sh.RegRead(Key & "WSHTest\string2")
Debug.Print sh.RegRead(Key & "WSHTest\string3")
Debug.Print sh.RegRead(Key & "WSHTest\int")
sh.RegDelete Key & "WSHTest\"

End Sub
================================

Regards John
 
Based on an added suggestion from one of the
Windows MVP's, I created a simple function:
==================================
Public Function GetDfltEmailClient() As String
Dim objShell As Object

Set objShell = CreateObject("WScript.Shell")
GetDfltEmailClient = objShell.RegRead("HKLM\SOFTWARE\Clients\Mail\")
End Function
==================================
What's the down-side of coding to a reliance on the
Script Host when one doesn't know exactly where
the code might end up. It's not likely that it would be
a machine any older than Windows 98SE running
Access2000 or later.

Bill
 
Hi Bill,

You may find that on some machines, scripting is disabled as a security
measure. Using the API registry functions directly rather than as
wrapped in the WScript.Shell object will mimise the chance of this and
other dependency problems.
 
Ah yes, that is a distinct possibility.

I looked quickly at the RegEnumValue() API function, but
I'm not sure I quite got what part of all of what I read applies
to a simple reading of Registry key value. Maybe I'm just getting
lazy, but I was trying to avoid the amount of time it would take
to figure out how to use what could be found at the site you
recommended, as I've not yet ventured into some of the features
I see being used in their examples. (Your help with this would
be appreciated if you have the time... hint hint)

Thanks for the heads-up about the disabled scripting possibility.

Bill
 
Do what I'd do:

1 Paste the entire example code from the API guide into a module, making
sure there's an Option Explicit declaration at the top.

2 Try to compile it. For each line that won't compile, either delete it
(e.g. Me.AutoRedraw = True) or change it to something that works in a
VBA module (e.g. change Private Sub Form_Load to Sub TestRegValue, and
Me.Print to Debug.Print).

3 Once it compiles, set a breakpoint near the start and step through the
code line by line until you understand what's going on.

4 Then modify it to do what you need.

If that's too much trouble, use the Windows Scripting solution for now
and study the API later.



Ah yes, that is a distinct possibility.

I looked quickly at the RegEnumValue() API function, but
I'm not sure I quite got what part of all of what I read applies
to a simple reading of Registry key value. Maybe I'm just getting
lazy, but I was trying to avoid the amount of time it would take
to figure out how to use what could be found at the site you
recommended, as I've not yet ventured into some of the features
I see being used in their examples. (Your help with this would
be appreciated if you have the time... hint hint)

Thanks for the heads-up about the disabled scripting possibility.

Bill
 
Okay, here it is:
==================================================
Option Compare Database
Option Explicit

Const ERROR_NO_MORE_ITEMS = 259&
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long)
As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA"
(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias
"RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As
String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String,
lpcbClass As Long, lpftLastWriteTime As Any) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias
"RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal
lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long,
lpType As Long, lpData As Any, lpcbData As Long) As Long
Public Function ReadRegEmailClient() As String
Dim hKey As Long, Cnt As Long, sName As String, sData As String, Ret As
Long, RetData As Long
Dim rc As Long
Dim strValue As String

Const BUFFER_SIZE As Long = 255

Ret = BUFFER_SIZE

Cnt = 0

'Open the registry key containing the name of the default E-Mail client.

If RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Clients\Mail", hKey) = 0
Then
'initialize the buffers
sName = Space(BUFFER_SIZE)
sData = Space(BUFFER_SIZE)
Ret = BUFFER_SIZE
RetData = BUFFER_SIZE

ReadRegEmailClient = "" 'Set to zero-length string if default
name not recognized.

While RegEnumValue(hKey, Cnt, sName, Ret, 0, ByVal 0&, ByVal sData,
RetData) <> ERROR_NO_MORE_ITEMS _
And ReadRegEmailClient = ""
If RetData > 0 Then strValue = Left$(sData, RetData - 1)
If strValue = "Outlook" Or strValue = "Outlook Express" Then
ReadRegEmailClient = strValue

'Current value not recognized, prepare buffers for next value
Cnt = Cnt + 1
sName = Space(BUFFER_SIZE)
sData = Space(BUFFER_SIZE)
Ret = BUFFER_SIZE
RetData = BUFFER_SIZE
Wend

'Close the registry key
RegCloseKey hKey
Else
rc = MsgBox("Error in while calling RegOpenKey", vbCritical,
"FUNCTION: ReadRegEmailClient")
End If

MsgBox ReadRegEmailClient
End Function
==================================================

Thanks John, your guidance was great!
Bill

John Nurick said:
Do what I'd do:

1 Paste the entire example code from the API guide into a module, making
sure there's an Option Explicit declaration at the top.

2 Try to compile it. For each line that won't compile, either delete it
(e.g. Me.AutoRedraw = True) or change it to something that works in a
VBA module (e.g. change Private Sub Form_Load to Sub TestRegValue, and
Me.Print to Debug.Print).

3 Once it compiles, set a breakpoint near the start and step through the
code line by line until you understand what's going on.

4 Then modify it to do what you need.

If that's too much trouble, use the Windows Scripting solution for now
and study the API later.
 
Back
Top