Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I am using below code to get all the windows services in a server. I want to know the details of Domain\User, windows service is logged in with. How can achive this.
ServiceController[] lFnGetAllServicesInServer(string aStrServer)
{
    ServiceController[] lArrObjServiceController = null;
    try
    {

        lArrObjServiceController = ServiceController.GetServices(aStrServer.Trim());
        return lArrObjServiceController;
    }
    catch (Exception ex)
    {
        return lArrObjServiceController;
    }
    finally
    {
    }
}

Please help out


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 29-Jun-11 2:37am
v2

Got solved with this…

ManagementObjectSearcher lObjMSearcher =
                                    new ManagementObjectSearcher(lStrRemotePath
                                  , "select name, startname from Win32_Service where startname like 'DOMAINNAME'");
foreach (ManagementObject lObject in lObjMSearcher.Get())
{
string lStrServiceName = lObject["Name"].ToString();
       string lStrDomain = lObject["startname"].ToString();
}
 
Share this answer
 
v2
Comments
[no name] 30-Jun-11 3:33am    
Edited for Code Block
Thread.CurrentPrincipal.Identity.Name

should give you the username
 
Share this answer
 
Comments
Sreenath Gv 29-Jun-11 8:53am    
Hi,

I am looking for an windows service logged in domain.

Like lets say scheduler is installed in some server, here I want the domain name of the scheduler being logged in.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900