mirror of https://github.com/dahall/Vanara.git
Improved object disposal in SafeHTOKEN.FromThread
parent
803b31f094
commit
f196cb9baf
|
@ -6199,9 +6199,8 @@ namespace Vanara.PInvoke
|
|||
{
|
||||
if (Marshal.GetLastWin32Error() == Win32Error.ERROR_NO_TOKEN)
|
||||
{
|
||||
var pval = FromProcess(System.Diagnostics.Process.GetCurrentProcess());
|
||||
if (!DuplicateTokenEx(pval, TokenAccess.TOKEN_IMPERSONATE | desiredAccess, null, SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, TOKEN_TYPE.TokenImpersonation, out val))
|
||||
Win32Error.ThrowLastError();
|
||||
using var pval = FromProcess(null);
|
||||
val = pval.DuplicateImpersonate(SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, TokenAccess.TOKEN_IMPERSONATE | desiredAccess);
|
||||
if (!SetThreadToken(IntPtr.Zero, val))
|
||||
Win32Error.ThrowLastError();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue