usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Runtime.InteropServices;namespaceConsoleApplication5
{public classSharedTool : IDisposable
{//obtains user token
[DllImport("advapi32.dll", SetLastError = true)]static extern bool LogonUser(string pszUsername, string pszDomain, stringpszPassword,int dwLogonType, int dwLogonProvider, refIntPtr phToken);//closes open handes returned by LogonUser
[DllImport("kernel32.dll", CharSet =CharSet.Auto)]extern static boolCloseHandle(IntPtr handle);
[DllImport("Advapi32.DLL")]static extern boolImpersonateLoggedOnUser(IntPtr hToken);
[DllImport("Advapi32.DLL")]static extern boolRevertToSelf();const int LOGON32_PROVIDER_DEFAULT = 0;const int LOGON32_LOGON_NEWCREDENTIALS = 9;//域控中的需要用:Interactive = 2
private booldisposed;public SharedTool(string username, string pa