Feyyaz
Feyyaz

Reputation: 3216

ServiceController in a Windows Service

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

Upvotes: 0

Views: 1659

Answers (1)

Hans Passant
Hans Passant

Reputation: 942488

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.

Upvotes: 1

Related Questions