1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
if (LogonUser(_strUsername, _strDomain, _strPassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out hToken))
{
System.Diagnostics.Trace.TraceInformation(" Logon succeed!");
if (DuplicateToken(hToken, 2, out hTokenDuplicate))
{
oWindowsIdentity = new WindowsIdentity(hToken);
oWindowsImpersonationContext = oWindowsIdentity.Impersonate();
// Mon traitement
oWindowsImpersonationContext.Undo();
oWindowsImpersonationContext.Dispose();
oWindowsImpersonationContext = null;
oWindowsIdentity.Dispose();
oWindowsIdentity = null;
}
if (hTokenDuplicate != IntPtr.Zero) CloseHandle(hTokenDuplicate);
}
else
{
System.Diagnostics.Trace.TraceWarning(" Logon failed : " + GetLastError());
} |
Partager