Code Samples
The product includes numerous Visual Basic sample applications. All samples
include complete source code. For more detailed sample code please refer to the
sample applications.
Listing Windows Services
Listing 1 demonstrates listing all configured Windows services.
Private Sub ListServices()
' Open the service manager
Dim ServiceManager As New ServiceManager
' Get the configured services
Dim v As Variant
v = ServiceManager.Services
If VarType(v) <> (vbVariant Or vbArray) Then Exit Sub
' Display the service names and status
Dim ServiceName() As Variant
Dim i As Integer
Dim Text As String
ServiceName = v
For i = LBound(ServiceName) To UBound(ServiceName)
' Service display name
Dim DisplayName As String
DisplayName = ServiceManager.DisplayName(ServiceName(i))
' Status
Select Case ServiceManager.Status(ServiceName(i))
Case Running
' The Service is running
Case StopPending
' The Service is stopping
Case Stopped
' The Service is not running
Case StartPending
' The Service is starting
Case Paused
' The Service is paused
Case PausePending
' The Service is pausing
Case ContinuePending
' The Service is continuing after a pause
End Select
' Startup
Select Case ServiceManager.Configuration(ServiceName(i)).StartType
Case AutoStart
' Automatic
Case BootStart
' Boot
Case DemandStart
" Manual
Case Disabled
' Disabled
Case SystemStart
'System Start
End Select
Next
End Sub
|
Listing 1 Listing Windows services
Starting a Windows Service
Listing 1 demonstrates starting a Windows service.
' Start the service
Dim ServiceManager As New ServiceManager
ServiceManager.Start "myservice"
|
Listing 2 Starting a Windows service
Stopping a Windows Service
Listing 2 demonstrates stopping a Windows service.
' Stop the service
Dim ServiceManager As New ServiceManager
ServiceManager.Stop "myservice"
|
Listing 3 Stopping a Windows service
|