.NET service detection (If Exists?) -


apologies if stupid question, i'm learning , i'm trying use documentation @ disposal , i've got reasonably far, i'm stuck on 1 last area.

problem

i'm trying detect if service exists/is running , dependent on result change label display status. - i've got status checks down, can't work out how check if service exists.

i'm using servicecontroller class.

current sub

public shared sub detectexchange()      dim service new servicecontroller("microsoft exchange service host")      if service.status.equals(servicecontrollerstatus.running) or service.status.equals(servicecontrollerstatus.startpending)         systemchecks.label9.text = "detected - running"      if service.status.equals(servicecontrollerstatus.stopped) or service.status.equals(servicecontrollerstatus.stoppending)         systemchecks.label9.text = "detected - not running"     end if   end sub 

my work far

i've been looking exists i've been toying strings if service.servicename , if service. looking through auto-complete options there's nothing there can see can detect if service exists @ all.

i have thought using getservices method, storing , searching service name , returning result that?

i tried being cheeky , add below in status check

     if service.status.equals(servicecontrollerstatus.running) or service.status.equals(servicecontrollerstatus.startpending)         systemchecks.label9.text = "detected - running"     else         systemchecks.label9.text = "not installed"     end if 

but realise terrible way of doing , wouldn't return value wanted see if return other status.

so added try statement suggested in comments, below working code.

public shared sub detectexchange()      dim service new servicecontroller("microsoft exchange service host")     try         if service.status.equals(servicecontrollerstatus.running) or service.status.equals(servicecontrollerstatus.startpending)             systemchecks.label9.text = "detected - running"         end if     catch ex exception         systemchecks.label9.text = "not installed"      end try      if service.status.equals(servicecontrollerstatus.running) or service.status.equals(servicecontrollerstatus.startpending)         systemchecks.label9.text = "detected - running"         systemchecks.label9.text = "detected - not running"     end if  end sub 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -