mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
e0579b0393
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4785 21ef857c-d57f-4fe0-8362-d861dc6d29cd
27 lines
578 B
C#
27 lines
578 B
C#
using System;
|
|
using ProcessHacker.Native.Api;
|
|
using ProcessHacker.Native.Objects;
|
|
|
|
namespace ProcessHacker.Native
|
|
{
|
|
public class ImpersonationContext : IDisposable
|
|
{
|
|
private bool _disposed;
|
|
|
|
public ImpersonationContext(TokenHandle token)
|
|
{
|
|
if (!Win32.ImpersonateLoggedOnUser(token))
|
|
Win32.Throw();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_disposed)
|
|
return;
|
|
|
|
Win32.RevertToSelf();
|
|
this._disposed = true;
|
|
}
|
|
}
|
|
}
|