LoadUserProfile fails with access denied error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have following piece of code (below) which impersonates a user and loads his profile. The strange this is if I run it from a console app it works just fine. But when I run it from inside an IIS application it gives access denied (5) error for the LoadUserProfile call. I have configured the IIS app to run under "user1" account - the same acct I use to log on interactively when I run it from an console app.
Both "user1" (which is going the impersonation) and "user2" (one that is being impersonated) belong to Administrators group on the server. This is happening on Win2003/IIS6. The profile in question (of user2) is not a roaming or temporary or mandatory.

Obviously there is something un-obvious is going on with the IIS app - but I cant think what. Any clues?

th
Jayan

if (!LogonUser("user2", "domain", "pwd", LOGON32_LOGON_SERVICE, LOGON32_PROVIDER_DEFAULT, &hToken)

pszErrMsg = "LogonUser failed."
throw false


if ( !ImpersonateLoggedOnUser(hToken)

pszErrMsg = "ImpersonateUser failed."
throw false


memset(&profileInfo, 0, sizeof(profileInfo))

profileInfo.dwSize = sizeof(profileInfo)
profileInfo.dwFlags = PI_NOUI
profileInfo.lpUserName = "user2"

if ( !LoadUserProfile(hToken, &profileInfo)

pszErrMsg = "ImpersonateUser failed."
throw false
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top