代码描述人生

.NET 相关技术 (大坏蛋的blog)

博客园 首页 新随笔 联系 订阅 管理

 

Using directives

namespace Impersonal
{
    
class Program
    
{
        
测试代码

        [DllImport(
"advapi32.dll", SetLastError = true)]
        
public extern static bool LogonUser(String lpszUsername, String lpszDomain,
            String lpszPassword, 
int dwLogonType,
            
int dwLogonProvider, ref IntPtr phToken);

        [DllImport(
"kernel32.dll", CharSet = CharSet.Auto)]
        
public extern static bool CloseHandle(IntPtr handle);

        [DllImport(
"advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        
public extern static bool DuplicateToken(IntPtr ExistingTokenHandle,
            
int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle);

        
public delegate void ImpersonatedWork();
        
/// <summary>
        
/// 以指定用户的身份去做一件事情
        
/// </summary>
        
/// <param name="UserName"></param>
        
/// <param name="PWD"></param>
        
/// <param name="WhatToDo"></param>

        public static void ImpersonateAndDo(string UserName, string PWD, ImpersonatedWork WhatToDo)
        
{
            
扮演用户
            
以新用户身份调用
            
取消扮演
        }

    }

}


最近太忙,好久不来,贴段刚写的代码,希望大家还记得我.
posted on 2004-10-27 20:22  大坏蛋  阅读(3082)  评论(1编辑  收藏  举报