Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Impersonate user question

Posted on 2002-05-30
6
Medium Priority
?
723 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

688 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