Solved

Impersonate user question

Posted on 2002-05-30
6
719 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 Scheduled Tasks 11 99
Need example 5 122
Problem to file 3 83
Where does legacy ASP.NET initialize language? 2 26
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…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…

828 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