Hi,
Use this method
private bool impersonateValidUser (String userName, String domain, String password)
{
TempWindowsIdentity WindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr = IntPtr.Zero tokenDuplicate;
if (RevertToSelf ())
{
if (LogonUser (userName, domain, password, LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, ref token)! = 0)
{
if (DuplicateToken (token, 2, ref tokenDuplicate)! = 0)
{
tempWindowsIdentity = new WindowsIdentity (tokenDuplicate);
impersonationContext tempWindowsIdentity.Impersonate = ();
if (impersonationContext! = null)
{
CloseHandle (token);
CloseHandle (tokenDuplicate);
return true;
}
}
}
}
if (token! = IntPtr.Zero)
CloseHandle (token);
if (tokenDuplicate! = IntPtr.Zero)
CloseHandle (tokenDuplicate);
return false;
}
private void undoImpersonation ()
{
impersonationContext.Undo ();
}
if u have any problems using it let me know