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.