public static void UnImpersonate() { // Stop impersonation and revert to the process identity if (impersonatedUser != null) { impersonatedUser.Undo(); } // Free the token if (token != IntPtr.Zero) { CloseHandle(token); } }