Hello,
I'm not very familar with using return true and false.
I found this code and would like to understand how to best use it.
public static bool IsServiceInstalled(string serviceName)
{
// get list of Windows services
ServiceController[] services = ServiceController.GetServices();
// try to find service name
foreach (ServiceController service in services)
{
if (service.ServiceName == "ServiceNameHere")
return true;
MessageBox.Show("true");
}
return false;
}
So, can someone show me a simple example of using this on say a form load.
Here is what I came up with so far.
ServiceController[] services = ServiceController.GetServices();
If (services == "ServiceName"
{
MessageBox.Show("Service: Found");
}
else
{
MessageBox.Show("Service: Not Found");
}
Thanks for the help!
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Nov 4, 2017, 2:07 AM