What's wrong in the below code

subramanyeswari ravinutala replied to Umapathy Kaliaperumal at 04-Jul-08 02:57

I used the following code to imperonate the normal user.  It is returning true.  But when i am writing into the reigstry it is returning the error code 5(access denied). is my code right?

bool ImpersonateUser::Logon(char* userName, char* domain, char* password)
{
 if(init_)
  Logoff();

 if(userName == NULL) // Must at least specify a username
 {
  errorCode_ = ERROR_BAD_ARGUMENTS;
  return false;
 }

  // Attempt to log on as that user
 BOOL bLoggedOn = FALSE;

 if(domain == NULL ) // Domain name was specified
  bLoggedOn = LogonUser(userName, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &userToken_);
 else
  bLoggedOn = LogonUser(userName, domain, password, LOGON32_LOGON_INTERACTIVE,/*LOGON32_LOGON_NEW_CREDENTIALS*/LOGON32_PROVIDER_WINNT50, &userToken_);

 if(!bLoggedOn)
 {
  errorCode_ = GetLastError();
  return false;
 }

  // Now impersonate them
 if(!ImpersonateLoggedOnUser(userToken_))
 {
  errorCode_ = GetLastError();
  return false;
 }

 init_ = true;
 return true;
}

//it is returning true

LONG lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("Software\\Wonderware\\InTouch\\Installation"),0,KEY_SET_VALUE,&hKey);

lRet ::RegSetValueEx(hKey,"InstallPath",0,REG_SZ,(BYTE*)("C:\\Windows"),dwSize);
 //it is retunging 5(access denied)

 

is something wrong with impersonation code

 

Thanks


Click here to sign in and reply. You could earn money via our $500 contest just for being helpful.
  impersonation in Vista - subramanyeswari ravinutala  04-Jul-08 12:14 12:14:07 AM
      ans to ur question - Umapathy Kaliaperumal  04-Jul-08 12:38 12:38:28 AM
      ans to ur question - Umapathy Kaliaperumal  04-Jul-08 12:38 12:38:48 AM
          What's wrong in the below code - subramanyeswari ravinutala  04-Jul-08 02:57 2:57:56 AM
      Check this out - santhosh kumar  04-Jul-08 01:28 1:28:12 AM
          not able to open - subramanyeswari ravinutala  04-Jul-08 02:58 2:58:18 AM
View Posts