Pretty much the same way as with Process (see my answer to your question on Processes.
Add reference to assembly
System.ServiceProcess
.
using System.ServiceProcess;
void DoWhatYouWantWithYourService(ServiceController controller) {
}
foreach (ServiceController controller in ServiceController.GetServices())
DoWhatYouWantWithYourService(controller);
There is also an overloaded version of
GetServices
for specified machine:
public static ServiceController[] GetServices(
string machineName
)
This is a complete answer. Who knows how do you want to "control" your services?