Impersonation to get user HKEY_CURRENT_USER does not work?

后端 未结 4 1481
甜味超标
甜味超标 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:12

    I'm guessing you're going to find that you're out of luck. It can't be done.

    If applications were able to impersonate an Administrator account and write values to the Registry in Windows, it would present a huge security hole. My guess is that the Registry.CurrentUser property will ALWAYS reference the user running your application...whether or not you try impersonation or not.

    EDIT

    Turns out that I didn't read the implementation details of the Impersonator code you were using. Your problem could be something completely different.

    Does your code refer to the Registry static class prior to your impersonation code being run? If so, that would be the problem. If you look at the Registry.CurrentUser property in Reflector, you'll see that it is set by the static constructor of the Registry object. Static constructors get called when the static object is first referenced.

    In your case, if you're referencing the Registry object (whether it involves CurrentUser or not) the static constructor is being called which is setting CurrentUser to your original user...not the Impersonated account.

提交回复
热议问题