





















using System.Security.Principal;
using System.Runtime.InteropServices;===========================================应用===================================================================
WindowsImpersonationContext wic = null;
try
{
wic = CreateIdentity (Uid,Domain,Pwd).Impersonate();
/*do something*/
/*do something*/
}
catch(Exception ex)
{
}
finally
{
if(wic != null) wic.Undo();
}
===============================================================================================================#region 虚拟管理员用户
public static WindowsIdentity CreateIdentity(string User, string Domain, string Password)
{
// The Windows NT user token.
IntPtr tokenHandle = new IntPtr(0);const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_NETWORK = 3;
tokenHandle
= IntPtr.Zero;// Call LogonUser to obtain a handle to an access token.System.Diagnostics.Debug.WriteLine(
"Created user token: " + tokenHandle);//The WindowsIdentity class makes a new copy of the token.[DllImport(
"kernel32.dll", CharSet=CharSet.Auto)]此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。