⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 C#开发教程 由浅入深 配有实例 是初学者的好帮手
💻 CS
字号:
using System; 
using System.Threading; 
using System.Security.Principal; 

using System.Runtime.InteropServices;

namespace UseRBS_Impersonate
{
    public class UseRBS_ImpersonateApp 
    { 
        [DllImport("advapi32.dll")]
        public static extern bool LogonUser(
            string lpszUsername, string lpszDomain, string lpszPassword, 
            int dwLogonType, int dwLogonProvider, out int phToken);

        public static void Main(string[] args) 
        { 
            try
            {
                int token1 = 0;
                bool loggedOn = LogonUser(
                    "Bill", "VENUS", "banana", 3, 0, out token1);
                IntPtr token2 = new IntPtr(token1);
                WindowsIdentity wi = new WindowsIdentity(token2);
                WindowsImpersonationContext wic = 
                    wi.Impersonate();
 
                Console.WriteLine("Principal/Identity values:");
                Console.WriteLine("Name: " +wi.Name); 
                Console.WriteLine("AuthenticationType: " 
                    +wi.AuthenticationType); 
                Console.WriteLine("IsAuthenticated: " +wi.IsAuthenticated); 
                Console.WriteLine("IsAnonymous: " +wi.IsAnonymous); 
                Console.WriteLine("IsGuest: " +wi.IsGuest); 
                Console.WriteLine("IsSystem: " +wi.IsSystem); 
                Console.WriteLine("Token: " +wi.Token); 

                wic.Undo();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        } 
    } 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -