实质上是通过WindowsIdentity.Impersonate()的方法,其中需要调用Win API来获得活用的Handle,用法其实很简单,因为在自己的代码中需要用到,就稍微封装了一下: ?public class IdentityImpersonation { ??[DllImport("advapi32.dll", SetLastError=true)]??public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, ???int dwLogonType, int dwLogonProvider, ref IntPtr phToken); ??[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]??public extern static bool DuplicateToken(IntPtr ExistingTokenHandle, ???int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle); ??[DllImport("kernel32.dll", CharSet=CharSet.Auto)]??public extern static bool CloseHandle(IntPtr handle); ??// 要模拟的用户的用户名、密码、域(机器名)??private String _sImperUsername;??private String _sImperPassword;??private String _sImperDomain;??// 记录模拟上下文??private WindowsImpersonationContext _imperContext;??private [...]
相关文章:
-
2021-07-05
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2021-10-21
-
2022-02-25
-
2022-12-23
-
2022-12-23
猜你喜欢
-
2022-12-23
-
2021-08-18
-
2022-01-08
-
2021-10-16
-
2021-09-16
-
2021-09-04
相关资源
-
下载
2022-12-06
-
下载
2022-12-02
-
下载
2023-03-21
-
下载
2023-01-06