Find which account a service is set to “Log On As”

一曲冷凌霜 提交于 2019-12-01 16:54:54
Stan R.

This is the only way I know of, I found it looking around and tested it, it works. Make sure you use the Service Name not it's Display Name, you will also need to add a reference to 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"]));
    }
}
serialhobbyist

How about using WMI and the Win32_Service class with the StartName parameter?

This article might help.

This will do your Job

 Get-WMIObject Win32_Service | Where-Object {$_.startname -ne "localSystem" }| Where-Object {$_.startname -ne "NT AUTHORITY\LocalService" } |Where-Object {$_.startname -ne "NT AUTHORITY\NetworkService" } |select startname, name 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!