C++ – Impersonation and Registry Manipulation in Vista\Win7

cimpersonationregistrywinapi

I need to create a program that has access to HKLM when running in a non-admin session. I have access to the admin credentials so impersonation seems to be an option.The sequence of Win32 calls is:

  1. LogonUser
  2. ImpersonateLoggedOnUser
  3. RegOpenKeyEx
  4. RegCreateKeyEx

The key is successfully created on XP/2003 and fails with 'Access Denied' on Vista/Win7. I am running as the same default domain user and impersonating the same domain admin in each of the scenarios. The 'Access Denied' is being generated by RegCreateKeyEx and obviously the key isn't being created.

Anyone have a clue to why this is happening?

Best Answer

An administrator on Windows Vista/7 doesn't have write access to HKLM by default either, they must elevate first. See Vista UAC: The Definitive Guide for details on launching a new process elevated since you cannot elevate an existing process.