gpt4 book ai didi

c# - 如何检查 Windows 身份是否正在模拟?

转载 作者:可可西里 更新时间:2023-11-01 09:44:45 24 4
gpt4 key购买 nike

是否可以检查 WindowsIdentity 是否正在模拟?

最佳答案

是的。只需检查 ImpersonationLevel WindowsIdentity 类的属性。

来自 MSDN:

Gets the impersonation level for the user

  • Anonymous - The server process cannot obtain identification information about the client, and it cannot impersonate the client
  • Delegation - The server process can impersonate the client's security context on remote systems
  • Identification - The server process can obtain information about the client...
  • Impersonation - The server process can impersonate the client's security context on its local system.
  • None

代码片段(已修改 MSDN example ):

var identity = WindowsIdentity.GetCurrent();
Console.WriteLine("Before impersonation: " + identity.Name);
Console.WriteLine("ImpersonationLevel: {0}", identity.ImpersonationLevel);

// Use the token handle returned by LogonUser.
using (WindowsIdentity newId = new
WindowsIdentity(safeTokenHandle.DangerousGetHandle()))
{
using (WindowsImpersonationContext impersonatedUser = newId.Impersonate())
{

// Check the identity.
identity = WindowsIdentity.GetCurrent();
Console.WriteLine("After impersonation: "+ identity.Name);
Console.WriteLine("ImpersonationLevel: {0}", identity.ImpersonationLevel);
}
}

输出:

enter image description here

更多

Tell me more

关于c# - 如何检查 Windows 身份是否正在模拟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31932927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com