Hi there,
Use impersonation + WINAPI:
-- BEGIN CODE --
using System;
using System.Runtime.InteropServices;
public sealed class Impersonation
{
private const int LOGON32_LOGON_INTERACTIVE = 2;
private const int LOGON32_LOGON_NETWORK_CLEARTEXT = 4;
private const int LOGON32_PROVIDER_DEFAULT = 0;
private enum SECURITY_IMPERSONATION_LEVEL : int
{
SecurityAnonymous = 0,
SecurityIdentification = 1,
SecurityImpersonation = 2,
SecurityDelegation = 3
}
[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
private extern static int DuplicateToken(
IntPtr hToken,
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
ref IntPtr hNewToken);
[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
private static extern int LogonUser(
string lpszUserName,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
private static System.Security.Principal.WindowsImpersonationContext
m_oContext = null;
public static bool Login(string strLogin, string strPassword, string
strDomain)
{
IntPtr hTokenDuplicate = IntPtr.Zero;
IntPtr hToken = IntPtr.Zero;
if (LogonUser(strLogin, strDomain, strPassword, LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, ref hToken) != 0)
{
if (DuplicateToken(hToken,
SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, ref hTokenDuplicate) !=
0)
{
m_oContext = new
System.Security.Principal.WindowsIdentity(hTokenDuplicate).Impersonate();
return (m_oContext != null);
}
}
return false;
}
public static void Logout()
{
if (m_oContext != null)
m_oContext.Undo();
}
}
-- END CODE --
Hope this helps