Solved

Impersonate user question

Posted on 2002-05-30
6
714 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
Comment Utility
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
Comment Utility
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
Comment Utility
>>and I don't want to keep all the tokens

You are keeping them. Or have you seen something that is called "CloseToken()"?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Author Comment

by:alex1234
Comment Utility
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
Comment Utility
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
Comment Utility
Saving this Q as a PAQ and refunding the points to the questionner

modulo

Community Support Moderat
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared 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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

9 Experts available now in Live!

Get 1:1 Help Now