
Script To Stop/Start NT Service
Quote:
> Hi has anyone developed a script to Stop or Start an NT service.
Here's a function I wrote (it requires ADSI):
'''''''''''''''''''''''''''''''''''''''''''''
'
' BounceService
'
' Returns TRUE if service stopped or started
' successfully.
'
'''''''''''''''''''''''''''''''''''''''''''''
Function BounceService(computer, service, action)
On Error Resume Next
Const ADS_SERVICE_RUNNING = 4
Const ADS_SERVICE_STOPPED = 1
Dim oService
' Assuming true here makes logic easier below...
BounceService = True
Set oService = GetObject("WinNT://" & computer & "/" & service
& ",Service")
' Attempt to stop or start service only if it's in opposite state,
' to avoid errors. Return False only if failed to stop/start.
Select Case action
Case "stop"
If oService.Status = ADS_SERVICE_RUNNING Then
oService.Stop
If Err.Number <> 0 Then BounceService = False
End If
Case "start"
If oService.Status = ADS_SERVICE_STOPPED Then
oService.Start
If Err.Number <> 0 Then BounceService = False
End If
End Select
Set oService = Nothing
End Function
Sent via Deja.com http://www.deja.com/
Before you buy.