Question

i am trying to write a service monitor tool like services.msc where can the attribute "log on as" be found using WMI

thanks

erez

Was it helpful?

Solution

Setting Windows Service Account - C# and WMI has some c# that might help - it should be easy enough to convert it to VB.

Specifically, the comment by asbf looks to have what you need.

string serviceName = "eventLog";
System.Management.SelectQuery query = new System.Management.SelectQuery(string.Format("select name, startname from Win32_Service where name = '{0}'", serviceName));
using (System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query))
{
   foreach (System.Management.ManagementObject service in searcher.Get())
   {
       Console.WriteLine(string.Format("Name: {0} - Logon : {1} ", service["Name"], service["startname"]));
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top