Impersonating CurrentUser from SYSTEM
Hey all, I've been searching for a very long time an easy way to impersonate current user while running in a "SYSTEM" user credentials. I haven't found any code that does it and actually works. So I managed to combine pieces of code from several places, and added some of my own. This helper class exposes 2 functions: 1. Get current user impersonated scope - in this scope you can do pretty much whatever you want in the current user credentials. 2. Start a process as current user. public static class ImpersonationUtils { private const int SW_SHOW = 5; private const int TOKEN_QUERY = 0x0008; private const int TOKEN_DUPLICATE = 0x0002; private const int TOKEN_ASSIGN_PRIMARY = 0x0001; private const int STARTF_USESHOWWINDOW = 0x00000001; private const int STARTF_FORCEONFEEDBACK = 0x00000040; private const int CREATE_UNICODE_ENVIRONMENT = 0x00000400; private const int TOKEN_IMPERSONATE = 0x0004; private const int TOKEN_...