Mike Smith

Mike Smith

  • NA
  • 5
  • 0

Using return true and false

Nov 3 2017 10:20 AM
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! 
 
 

Answers (1)