views:

70

answers:

1

Hello,

I'm trying to use ServiceController.GetServices() method to get the list of all the services. In a console application, it works OK, but I get an empty list if I call this method in a windows service. That seems an authentication issue, but I used all the account options ( Local System, Local Service, Network Service, User[which is a local admin] ), no luck.

Is there any suggestion?

Thanks

+1  A: 

Agreed, this has to be a user account privilege issue. Enumeration needs to get started by calling the native OpenSCManager() API function. This is a very privileged function, the SDK docs note that administrator access is required. You would have to configure the service and give it an admin login. Sounds like you already tried this. Worry about UAC a bit, then ask more questions about it at serverfault.com, presumed home of the security experts.

Hans Passant
I tried Artiom's suggestion, I created two ServiceController objects by service name, and they didn't give me any errors. So the problem is about getting all the services from a windows service. BTW, the user is already an admin. Thanks
sahs
Are these services running on a remote machine?
Hans Passant
@Hans, no they are local services. Simply the problem is that ServiceController.GetServices() method returns empty list. I still don't understand the problem :/.
sahs