Beispiel #1
0
        public IDisposable CreateThread(ThreadStart action)
        {
            uint threadId;
            var  duplicatedToken = IntPtr.Zero;

            Win32NativeMethods.DuplicateToken(logonToken, ImpersonationLevel.SecurityImpersonation, ref duplicatedToken);

            threadHandle = ThreadExtensions.CreateThread(() =>
            {
                if (!ThreadExtensions.SetThreadToken(IntPtr.Zero, duplicatedToken))
                {
                    throw new Exception("Unable to run thread as impersonated logon!");
                }

                action();
            }, out threadId);

            return(new ThreadDisposable(threadHandle, threadId));
        }
Beispiel #2
0
 public void Revert()
 {
     Win32NativeMethods.RevertToSelf();
 }