在Windows线程中模拟其他用户上下文!
2009-09-11 13:56
204 查看
在Windows线程中模拟其他用户上下文,需要使用WindowsIdentity.Impersonate方法!同时还需要用LogonUser API来获取安全令牌,代码如下:
using System.Runtime.InteropServices; using System.Security.Principal; class Program { [DllImport("Advapi32.dll")] static extern bool LogonUser( string sUserName, string sDomain, string sUserPassword, uint dwLogonType, uint dwLogonProvider, out System.IntPtr token); [DllImport("Kernel32.dll")] static extern void CloseHandle(System.IntPtr token); static void Main() { System.IntPtr pToken; if(LogonUser( "Administrator", "DomainName", "Password", 2, 0, out pToken)){ WindowsIdentity.Imersonate(pToken);//模拟用户 WindowsIdentity id=WindowsIdentity.GetCurrent(); Console.WriteLine(id.Name); CloseHandle(pToken);
相关文章推荐
- WebApi 数据保护操作未成功。这可能是由于未为当前线程的用户上下文加载用户配置文件导致的。当线程执行模拟时,可能会出现此情况。","ExceptionType":"System.Security.Cryptography.CryptographicException","StackTrace
- ASP.NET中启用Windows集成验证,怎样在调用System.DirectoryServices下的组件时传递安全上下文,也就是说当前用户凭据,来实现权限管理
- 【GamingAnywhere源码分析之知识补充五】Windows模拟用户session完成存储权限控制
- ASP.NET模拟其他用户进行关机
- 如何向其他线程的地址空间中注入代码并在这个线程的上下文中执行之
- [Windows 8小技巧]开启“以其他身份用户运行”程序
- Windows的用户管理中的用户模拟 impersonate
- 异常信息:CLR无法从COM 上下文0x645e18 转换为COM上下文0x645f88,这种状态已持续60秒。拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows 消息的情况下处理一个运行时间非常长的操作.这种情况通常会影响到
- 使用 Web API 模拟其他用户
- 异常信息:CLR无法从COM 上下文0x645e18 转换为COM上下文0x645f88,这种状态已持续60秒。拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows 消息的
- 如何向其他线程的地址空间中注入代码并在这个线程的上下文中执行之
- ASP.NET模拟其他用户进行关机
- windows线程用户模式-关键段
- 模拟Windows登录用户进行特殊操作
- Windows系统的四个重要概念——进程、线程、虚拟内存、内核模式和用户模式
- Windows 设置了文件夹共享,删除默认Everyone共享,设置其他用户共享之后打不开的问题
- 网络编程(43)—— windows平台下创建线程的四种方法(二)之用户界面线程
- Windows编程-- 用户方式中线程的同步---原子访问:互锁的函数家族
- C#执行Shell命令,WebService需要访问其他服务器的文件时,在IIS中登入Windows用户
- windows 10 中为开始菜单中的应用程序增加“以其他用户身份运行”菜单