C#-登录会话列表我想知道如何获取登录用户列表。我可以打开Windows任务管理器,查看“用户”选项卡,然后查看谁在PC上登录。我如何获得该用户列表。谢谢。看一下WMI。您可以使用System.Management命名空间:System.Management.ConnectionOptionsmyConnectionOptions=newSystem.Management.ConnectionOptions();myConnectionOptions.Impersonation=System.Management.ImpersonationLevel.Impersonate;System.Management.ManagementScope对象服务;System.Management.ManagementObjectSearchermyObjectSearcher;System.Management.ManagementObjectCollectionmyCollection;尝试{objwmiservice=newSystem.Management.ManagementScope(("\\"+(HostOrIP+"\root\cimv2")),myConnectionOptions);objwmiservice.Connect();myObjectSearcher=newSystem.Management.ManagementObjectSearcher(objwmiservice.Path.ToString(),"从Win32_ComputerSystem选择用户名");myObjectSearcher.Options.Timeout=newTimeSpan(0,0,0,0,7000);myCollection=myObjectSearcher.Get();foreach(System.Management.ManagementObjectmyObjectinmyCollection){if(!(myObject.GetPropertyValue("Username")==null)){stringUserx=myObject.GetPropertyValue("Usernamee").ToString();intposx=Userx.LastIndexOf("\");if((posx>0)){Userx=Userx.Substring((posx+1));返回Userx.ToUpper();}}}返回””;}赶上(异常){返回“”;我从这个链接得到的以上是C#学习教程:C#-登录会话列表分享的所有内容,如果对大家有用还需要了解更多关于C#学习教程,希望大家多多关注对吧~本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: