惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
月光博客
月光博客
人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
Vercel News
Vercel News
MyScale Blog
MyScale Blog
爱范儿
爱范儿
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
H
Help Net Security
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
宝玉的分享
宝玉的分享
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
博客园 - 叶小钗
D
Docker

博客园 - Rain@sz

C#多线程编程(转) 调用webservice类(转) webService动态编译(编译在内存中,不会有权限问题) 什么是AOP? (摘) 阿里巴巴信息抓取器 脏读、不可重复读和虚读。(数据库)摘 c#写Activex控件(.Net 2.0) sql server 2005分页存储过程和sql server 2000分页存储过程(摘) net的辅助工具 ajax基本函数--js Memento Pattern(备忘录模式) Interpreter Pattern(解释器模式) State Pattern(状态模式) Mediator Pattern(中介者模式) 动态调用Webservice(摘) 分页--页脚控件 RSS 标准 DP-還未添加 DP-职责链模式(Chain of Responsibility)
SPS中模拟登陆
Rain@sz · 2008-08-04 · via 博客园 - Rain@sz

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.
   bool returnValue = LogonUser(User, Domain, Password, 
    LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT,
    
ref tokenHandle);if (false == returnValue)
   {
    
int ret = Marshal.GetLastWin32Error();
    
throw new Exception("LogonUser failed with error code: " +  ret);
   }

   System.Diagnostics.Debug.WriteLine(

"Created user token: " + tokenHandle);//The WindowsIdentity class makes a new copy of the token.
   
//It also handles calling CloseHandle for the copy.
   WindowsIdentity id = new WindowsIdentity(tokenHandle);
   CloseHandle(tokenHandle);
   
return id;
  }
  [DllImport(
"advapi32.dll", SetLastError=true)]
  
private static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,
   
int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

  [DllImport(

"kernel32.dll", CharSet=CharSet.Auto)]
  
private extern static bool CloseHandle(IntPtr handle);#endregion 虚拟管理员用户