MAPI/CDO from an NT Service
-
I've got some confusing code to try and fix. It appears to be using CDO to send a message and it works fine from the command line. however, from an NT service it fails due a MAPI Logon error. I know this is usually to do with the profile, but I now think it's down to CDO as if I replace the CDO logon code with a standard MAPILogonEx() call, it logs on with no problem. I guess it may be down to the parameter the previous developer wasn't passing in at logon time, for example, MAPI_NT_SERVICE. I don't know how to do this in CDO and I cannot find any documentation. Can anyone help? Can anyone suggest any links to info? Here's a brief summary of the code I need to get working: 1.
CLSIDFromPogID()
returns "MAPI.Session
"CLSID
. 2.CoCreateInstance()
on the MAPICLSID
returnsIDispatch
interface. 3. Calls theLogon()
method on theIDispatch
interface with several parameters (this is where I believe I should be able to pass my extra parameters), but how? 4. CallGetIDsOfNames()
to get theDISPID
for the method required. 5. CallIDispatch::Invoke()
with the named member ID "The folly of man is that he dreams of what he can never achieve rather than dream of what he can." "If you think education is expensive, try ignorance." -
I've got some confusing code to try and fix. It appears to be using CDO to send a message and it works fine from the command line. however, from an NT service it fails due a MAPI Logon error. I know this is usually to do with the profile, but I now think it's down to CDO as if I replace the CDO logon code with a standard MAPILogonEx() call, it logs on with no problem. I guess it may be down to the parameter the previous developer wasn't passing in at logon time, for example, MAPI_NT_SERVICE. I don't know how to do this in CDO and I cannot find any documentation. Can anyone help? Can anyone suggest any links to info? Here's a brief summary of the code I need to get working: 1.
CLSIDFromPogID()
returns "MAPI.Session
"CLSID
. 2.CoCreateInstance()
on the MAPICLSID
returnsIDispatch
interface. 3. Calls theLogon()
method on theIDispatch
interface with several parameters (this is where I believe I should be able to pass my extra parameters), but how? 4. CallGetIDsOfNames()
to get theDISPID
for the method required. 5. CallIDispatch::Invoke()
with the named member ID "The folly of man is that he dreams of what he can never achieve rather than dream of what he can." "If you think education is expensive, try ignorance."Windows does not load the user's configured profile when logging on as a service. This may be the source of your problem. You could try calling
LoadUserProfile
before callingLogon
. -
Windows does not load the user's configured profile when logging on as a service. This may be the source of your problem. You could try calling
LoadUserProfile
before callingLogon
.No, I'm definitely specifying the user profile and password if necessary. They are passed as the first two parameters to the Logon method via MAPI's
IDispatch
interface. I know it works just fine as an NT service because, as I said, replacing the CDO code with Extended MAPI, works fine. Unfotunately, if I were to use Extended MAPI there is a lot of extra work to do replacing all the existing code... "The folly of man is that he dreams of what he can never achieve rather than dream of what he can." "If you think education is expensive, try ignorance." -
No, I'm definitely specifying the user profile and password if necessary. They are passed as the first two parameters to the Logon method via MAPI's
IDispatch
interface. I know it works just fine as an NT service because, as I said, replacing the CDO code with Extended MAPI, works fine. Unfotunately, if I were to use Extended MAPI there is a lot of extra work to do replacing all the existing code... "The folly of man is that he dreams of what he can never achieve rather than dream of what he can." "If you think education is expensive, try ignorance."Sorry, I mean 'user's profile' in the sense of the registry entries under
HKEY_USERS
and mappingHKEY_CURRENT_USER
to the appropriate key underHKEY_USERS
. This is not done for a batch, service or network logon, it's only done byUSERENV.EXE
for an interactive logon. -
Sorry, I mean 'user's profile' in the sense of the registry entries under
HKEY_USERS
and mappingHKEY_CURRENT_USER
to the appropriate key underHKEY_USERS
. This is not done for a batch, service or network logon, it's only done byUSERENV.EXE
for an interactive logon.That's not a problem. I specify the MAPI_EXPLICIT_PROFILE flag. All I need to do then is specify a valid profile and password if required. "The folly of man is that he dreams of what he can never achieve rather than dream of what he can." "If you think education is expensive, try ignorance."