Impersonation to get user HKEY_CURRENT_USER does not work?

后端 未结 4 1469
甜味超标
甜味超标 2021-01-23 18:20

I am attempting to Impersonate an administrator account from a LocalSystem Service in order to get data from administrators HKEY CURRENT USER registry - in order to impersonate

4条回答
  •  天涯浪人
    2021-01-23 19:10

    By default the HKEY_CURRENT_USER handle is cached on a process wide basis. So when you impersonate a user and then access the current user hive you will be accessing the hive of the user that started the process not the user being impersonated. This is true for all Win32 processes not just .Net. If you wish to disable this caching so that all current user calls go to the correct user hive under HKEY_USERS then you must call RegDisablePredefinedCache via pInvoke.

    Be warned that if the user being impersonated has not had their profile loaded then any CurrentUser requests will be forwarded to the .DEFAULT user. So you may also need to call LoadUserProfile.

    Disabling the handle caching will also cause a slight slowdown in all CurrentUser requests.

提交回复
热议问题