exchangefreaks.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Impersonsate User and Access Mailbox

 
Post new topic   Reply to topic    exchangefreaks.com Forum Index -> MS Exchange Applications
Author Message
Brent



Joined: 05 Aug 2007
Posts: 1

PostPosted: Mon Sep 08, 2003 1:33 pm    Post subject: Impersonsate User and Access Mailbox Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    exchangefreaks.com Forum Index -> MS Exchange Applications All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group