📄 class1.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 + -