Solved

Impersonate user question

Posted on 2002-05-30
6
716 Views
Last Modified: 2013-12-03
I have a service that runs under LocalSystem account and I need access to MAPI which requires to impersonate LocalSystem with an other user (e.g. user1). Impersonation works back and forth only 3 times, after the forth impersonation (no errors from APIs reported) MapiLogon fails as if I user LocalSystem account. Why only 3 times?

Here is the sequence:

LogonUser(user1, ...)
ImpersonateLoggedOnUser(...)
LoadUserProfile(...)
RegCloseKey(HKEY_CURRENT_USER)

*** Call MAPI sfuff here ***

UnloadUserProfile()
RevertToSelf()

Again, no errors were reported from all these APIs, just the third time MAPI stuff fails. Why?

0
Comment
Question by:alex1234
  • 2
  • 2
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7045414
Are you calling "LogonUser()" each time? I mean, once you have the user token, you can keep it and just call "ImpersonateLoggedOnUser()" multiple times. This could be the problem...
0
 
LVL 1

Author Comment

by:alex1234
ID: 7045427
I need to call it multiple times because this 'impersonate' sequence once called needs to serve different users (credentials) and I don't want to keep all the tokens which I might never need again
0
 
LVL 86

Expert Comment

by:jkr
ID: 7045517
>>and I don't want to keep all the tokens

You are keeping them. Or have you seen something that is called "CloseToken()"?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:alex1234
ID: 7046885
I've seen CloseHandle(). Still, I want the entire sequence

LogonUser(user1, ..., hToken)
ImpersonateLoggedOnUser(...)
LoadUserProfile(...)
RegCloseKey(HKEY_CURRENT_USER)

*** Call MAPI sfuff here ***

CloseHandle(hToken)
UnloadUserProfile()
RevertToSelf()

to work multiple times, not just 3 times. There must be something missing here, but what..?


0
 

Expert Comment

by:modulo
ID: 7719507
Dear expert(s),

A request has been made to close this Q in CS:
http://www.experts-exchange.com/Community_Support/Q_20454657.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 7754645
Saving this Q as a PAQ and refunding the points to the questionner

modulo

Community Support Moderat
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Duplicates in Aggregate Query 3 34
What is Runtime?  What is Middleware?  Azure stack 1 266
Issue testing the Class Library 4 48
wordpress limitations 4 105
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now