Files
mirror-processhacker/branches/ph-plugins/ProcessHacker.Native/ImpersonationContext.cs
T
wj32 504ee67b17 new ph-plugins branch
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@2148 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2009-10-12 02:21:30 +00:00

27 lines
601 B
C#

using System;
using ProcessHacker.Native.Api;
using ProcessHacker.Native.Objects;
namespace ProcessHacker.Native
{
public class ImpersonationContext : IDisposable
{
private bool _disposed = false;
public ImpersonationContext(TokenHandle token)
{
if (!Win32.ImpersonateLoggedOnUser(token))
Win32.ThrowLastError();
}
public void Dispose()
{
if (!_disposed)
{
Win32.RevertToSelf();
_disposed = true;
}
}
}
}