Csharp/C#教程:查找服务设置为“登录身份”的帐户分享


查找服务设置为“登录身份”的帐户

如何查找用户帐户( 本地系统/用户等 )服务设置为运行(“登录为”)?

与此类似问题不同,此代码无法在服务本身内运行,并且服务可能无法运行。

System.ServiceProcess.ServiceController类具有获取状态但不是“登录为”用户的有用方法。

这是我所知道的唯一方式,我发现它环顾四周并测试它,它的工作原理。 确保使用服务名称而不是显示名称,您还需要添加对System.Management的引用

string serviceName = "aspnet_state"; SelectQuery query = new System.Management.SelectQuery(string.Format( "select name, startname from Win32_Service where name = '{0}'", serviceName)); using (ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query)) { foreach (ManagementObject service in searcher.Get()) { Console.WriteLine(string.Format( "Name: {0} - Logon : {1} ", service["Name"], service["startname"])); } } 

如何将WMI和Win32_Service类与StartName参数一起使用?

这篇文章可能有帮助。

这将完成你的工作

上述就是C#学习教程:查找服务设置为“登录身份”的帐户分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

  Get-WMIObject Win32_Service | Where-Object {$_.startname -ne "localSystem" }| Where-Object {$_.startname -ne "NT AUTHORITYLocalService" } |Where-Object {$_.startname -ne "NT AUTHORITYNetworkService" } |select startname, name 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/991123.html

(0)
上一篇 2021年12月23日
下一篇 2021年12月23日

精彩推荐