none
How do I get Log On As (userid) from System.ServiceProcess.ServiceController.GetServices RRS feed

  • Question

  • I have the latest .NET and Visual Studio 2017 and can't seem to get the "Log On As" userid in the services list by using the function System.ServiceProcess.ServiceController.GetServices(mycomputer). I looked at all the parameters associated with ServiceController and can't seem to get that value. Someone suggested in my Google search to use the ServiceName but that is not working for me. Anyone know how I can pull that value when I loop through the list of services?

    Tuesday, July 24, 2018 11:42 AM

Answers

All replies

  • You can get it with WMI and Win32_Service (StartName)

    • Marked as answer by Petey1234 Tuesday, July 24, 2018 1:39 PM
    Tuesday, July 24, 2018 12:44 PM
  • Ah got it, thanks!!!! Only thing is I have to do a connect with each service so it sloooooows things down. It's too bad I couldn't get this information through GetServices.

       string computerpath = "\\\\" + theComputerName + "\\root\\cimv2:";
       ManagementObject wmiService;
       wmiService = new ManagementObject(computerpath + "Win32_Service.Name='" + sc.ServiceName + "'");
       wmiService.Get();
       string serviceAccount = wmiService["StartName"].ToString();



    • Edited by Petey1234 Tuesday, July 24, 2018 2:47 PM
    Tuesday, July 24, 2018 1:41 PM