Controlling services

  • Thread starter Thread starter VBTricks.de.vu Webmaster
  • Start date Start date
V

VBTricks.de.vu Webmaster

Hello,

I'm trying to speed up windows start a bit. Therefore I want to start
some services at a later point of time and some only if I run the
application which needs the services.
The first point is no problem, "net start" allows manual start of a
service. The tricky one is the second. Is there any .net class that
allows controling the services? I need to check if a specific service
(identified by name) is running and to start it, if it is not running.


Thanks in advance,

Stefan

--
___________________________________www.VBTricks.de.vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
_____________________________________________________
 
Hi,

The servicecontroller class does what you want.

Dim s As System.ServiceProcess.ServiceController

For Each s In System.ServiceProcess.ServiceController.GetServices
If s.ServiceName = "MSSQLSERVER" Then
If s.Status = ServiceProcess.ServiceControllerStatus.Stopped
Then s.Start()
End If
's.Stop to stop
's.Start to start
's.Pause to pause
Next


Ken
 
VBTricks.de.vu Webmaster said:
The first point is no problem, "net start" allows manual start of a
service. The tricky one is the second. Is there any .net class that
allows controling the services? I need to check if a specific service
(identified by name) is running and to start it, if it is not running.

Take a look at the 'ServiceController' class.
 
Back
Top