Snedker <morten@nospam_dbconsult.dk> wrote:
> On Fri, 21 Jun 2002 18:33:59 +0200, "Mikkel Bundgaard"
> <mikkelbu@teliamail.dk> wrote:
>
> Takker, vil prøve at kigge på det.
>
>> Hvad skal du bruge det til ???
>
> Et lille vb-program som checker for indkomne filer. Disse skal
> behandles og sendes videre til andre. Der er ønske om at det skal
> sendes udenom Outlook, for ikke at fylde outbox'en.
>
> Det var mere for ikke at skulle angive smtp-server specifikt for
> hver kunde - men at programmet selv kunne finde ud af det.
>
> mvh
> Morten Snedker
Hej Morten
Nedenstående koddestump tilgår registreringsdatabasen og udhenter
den ønskede oplysning. Jeg har kun testet det på min egen computer
(Win98SE og OE 5.5), men her giver den det korrekte svar, så må du
se om du kan bruge det til noget i outlook
De fleste af erklæringerne og functionerne er taget fra
http://support.microsoft.com/default.aspx?scid=kb;DA;q145679
Option Explicit
Public Const REG_SZ As Long = 1
Public Const REG_DWORD As Long = 4
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const ERROR_NONE = 0
Public Const ERROR_BADDB = 1
Public Const ERROR_BADKEY = 2
Public Const ERROR_CANTOPEN = 3
Public Const ERROR_CANTREAD = 4
Public Const ERROR_CANTWRITE = 5
Public Const ERROR_OUTOFMEMORY = 6
Public Const ERROR_ARENA_TRASHED = 7
Public Const ERROR_ACCESS_DENIED = 8
Public Const ERROR_INVALID_PARAMETERS = 87
Public Const ERROR_NO_MORE_ITEMS = 259
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0
Declare Function RegCloseKey _
Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Declare Function RegCreateKeyEx _
Lib "advapi32.dll" Alias "RegCreateKeyExA" ( _
ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal Reserved As Long, ByVal lpClass As String, _
ByVal dwOptions As Long, ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, phkResult As Long, _
lpdwDisposition As Long) As Long
Declare Function RegOpenKeyEx _
Lib "advapi32.dll" Alias "RegOpenKeyExA" ( _
ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, _
phkResult As Long) As Long
Declare Function RegQueryValueExString _
Lib "advapi32.dll" Alias "RegQueryValueExA" ( _
ByVal hKey As Long, ByVal lpValueName As String, _
ByVal lpReserved As Long, lpType As Long, _
ByVal lpData As String, lpcbData As Long) As Long
Declare Function RegQueryValueExLong _
Lib "advapi32.dll" Alias "RegQueryValueExA" ( _
ByVal hKey As Long, ByVal lpValueName As String, _
ByVal lpReserved As Long, lpType As Long, _
lpData As Long, lpcbData As Long) As Long
Declare Function RegQueryValueExNULL _
Lib "advapi32.dll" Alias "RegQueryValueExA" ( _
ByVal hKey As Long, ByVal lpValueName As String, _
ByVal lpReserved As Long, lpType As Long, _
ByVal lpData As Long, lpcbData As Long) As Long
Declare Function RegSetValueExString _
Lib "advapi32.dll" Alias "RegSetValueExA" ( _
ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, _
ByVal lpValue As String, ByVal cbData As Long) As Long
Declare Function RegSetValueExLong _
Lib "advapi32.dll" Alias "RegSetValueExA" ( _
ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, _
lpValue As Long, ByVal cbData As Long) As Long
Function QueryValueEx(ByVal lhKey As Long, _
ByVal szValueName As String, vValue As Variant) As Long
Dim cch As Long
Dim lrc As Long
Dim lType As Long
Dim lValue As Long
Dim sValue As String
On Error GoTo QueryValueExError
' Determine the size and type of data to be read
lrc = RegQueryValueExNULL(lhKey, _
szValueName, 0&, lType, 0&, cch)
If lrc <> ERROR_NONE Then Error 5
Select Case lType
' For strings
Case REG_SZ:
sValue = String(cch, 0)
lrc = RegQueryValueExString(lhKey, _
szValueName, 0&, lType, sValue, cch)
If lrc = ERROR_NONE Then
vValue = Left$(sValue, cch - 1)
Else
vValue = Empty
End If
' For DWORDS
Case REG_DWORD:
lrc = RegQueryValueExLong(lhKey, _
szValueName, 0&, lType, lValue, cch)
If lrc = ERROR_NONE Then vValue = lValue
' Else
Case Else
'all other data types not supported
lrc = -1
End Select
QueryValueExExit:
QueryValueEx = lrc
Exit Function
QueryValueExError:
Resume QueryValueExExit
End Function
Private Function QueryValue(sKeyName As String, _
sValueName As String) As String
Dim lRetVal As Long 'result of the API functions
Dim hKey As Long 'handle of opened key
Dim vValue As Variant 'setting of queried value
lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, _
KEY_QUERY_VALUE, hKey)
lRetVal = QueryValueEx(hKey, sValueName, vValue)
RegCloseKey (hKey)
QueryValue = vValue
End Function
Public Function getDefaultSMTP() As String
Const strAccLoc As String = _
"Software\Microsoft\Internet Account Manager"
Dim strLocation As String
strLocation = QueryValue(strAccLoc, "Default Mail Account")
If Len(strLocation) > 0 Then
getDefaultSMTP = QueryValue(strAccLoc _
& "\Accounts\" & strLocation, "SMTP Server")
End If
End Function
Håber du kan bruge det til noget
--
Mikkel Bundgaard
Student at IT University of Copenhagen
http://officehelp.gone.dk
Codito, Ergo Sum