zoukankan      html  css  js  c++  java
  • 一个在.net下进行用户模拟的类

    实质上是通过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 [...]
  • 相关阅读:
    [CF786B] Legacy
    [CF833B] The Bakery
    [JSOI2008] 最小生成树计数
    [SDOI2010] 外星千足虫
    [POJ1830] 开关问题
    [Luogu1365] WJMZBMR打osu! / Easy
    [Noip2016] 换教室
    [NOI2002] 荒岛野人
    [计蒜之道复赛 2018] 贝壳找房计数比赛
    [SDOI2014] 旅行
  • 原文地址:https://www.cnblogs.com/kaneboy/p/2333712.html
Copyright © 2011-2022 走看看