Solved

Impersonate user question

Posted on 2002-05-30
6
717 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem updating Access table using VB code 8 51
Windows 10 Scheduled Tasks 11 84
wordpress limitations 4 114
What .NET website keeps me current? 9 68
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

18 Experts available now in Live!

Get 1:1 Help Now