I don’t get ImpersonateSelf(). Suppose my code is run in some host process. That host process created a new thread and adjusted the thread security so that the thread has minimal privileges and now that new thread executes my code.
My code calls
ImpersonateSelf( SecurityImpersonation );
What effect will it have? Will it reset all privileges adjustments done for that thread?
Yes. It duplicates the process token and assigns that to be the impersonation token of the current thread. The privileges from the old token are irrelevant because the thread isn’t using that token anymore. If you want to merge the privileges, use GetTokenInformation to get the old privileges and duplicate and assign the impersonation token yourself.