以下是代码
using System;
using System.Security.Principal;
using System.Security.Permissions;
using System.Runtime.InteropServices;namespace LG
{
class Lg
{
[DllImport("advapi32.dll",EntryPoint = "LogonUser",SetLastError = true, CharSet=CharSet.Auto)]
public static extern bool LogonUser(String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken); public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_PROVIDER_DEFAULT = 0; static void Login()
{
IntPtr token = IntPtr.Zero; if(LogonUser("forbes",".","1234",LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,ref token)!=0)
{
Console.WriteLine("OK");
}
else
{
Console.WriteLine("NO OK");
}
} static void Main(string[] argu)
{
Login();
Console.ReadLine();
} }
}