I am writing an application in VB6 that will prompt a user to enter
their username and password. It will then call the LogonUser API to
log the user in, then call ImpersonateLoggedOnUser. After that, it
will log them in to Exchange to send an email using CDO.
The computer is on a domain, but only logged in as a local user. The
user has the 'Act as a part of the OS' right assigned.
The LogonUser and ImpersonateLoggedOnUser work fine. When I enter a
domain user, it logs them in and I have verified that I can access to
files that only that user has rights to. So this appears to be working
fine.
When I call the Session.Logon command in CDO, I get the error "You do
not have permission to log on". I have tried all sorts of scenarios,
but cannot get it to work.
Here is some code I've been testing with:
Dim hToken&
Dim strProfile As String
Dim oSession As MAPI.Session
If LogonUser(txtUsername.Text, txtDomain.Text, txtPassword.Text,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, hToken&) = 0 Then
ok = False
MsgBox "not logged in to windows"
Else
If ImpersonateLoggedOnUser(hToken&) = 0 Then
ok = False
If hToken& 0 Then CloseHandle (hToken&)
Else
ok = True
End If
If hToken& 0 Then CloseHandle (hToken&)
End If
If ok Then
Set oSession = New MAPI.Session
strProfile = "w2ksvr" & vbLf & txtUsername.Text
oSession.Logon "", "", False, False, , , strProfile
MsgBox "you are logged in!"
oSession.Logoff
End If
I know I am assuming the NT and Exchange usernames are the same, but
for now they are. I'll figure out how to get the mailbox from the
username later.
Any ideas would be greatly appreciated.
Thanks,
Brent
Archived from group: microsoft>public>exchange>applications