Script To Stop/Start NT Service 
Author Message
 Script To Stop/Start NT Service

Hi has anyone developed a script to Stop or Start an NT service.  Have used
the Net Stop/Start command in the past just using batch files, but need to
stop a couple services which are not available through this command. For
example would like to stop SMS services.

Thanks in advance.



Fri, 12 Apr 2002 03:00:00 GMT  
 Script To Stop/Start NT Service

Use ADSI power features...

Official ADSI reference:
 http://msdn.microsoft.com/library/psdk/adsi/adsistartpage_7wrp.htm

Helpful ADSI samples:
 http://cwashington.netreach.net/script_repository/adsifaq.asp

.Enjoy.
Legolas

Quote:

> Hi has anyone developed a script to Stop or Start an NT service.  Have used
> the Net Stop/Start command in the past just using batch files, but need to
> stop a couple services which are not available through this command. For
> example would like to stop SMS services.

> Thanks in advance.



Fri, 12 Apr 2002 03:00:00 GMT  
 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.



Sat, 13 Apr 2002 03:00:00 GMT  
 Script To Stop/Start NT Service
Thanks for the help all will give it a try.


Quote:
> Hi has anyone developed a script to Stop or Start an NT service.  Have
used
> the Net Stop/Start command in the past just using batch files, but need to
> stop a couple services which are not available through this command. For
> example would like to stop SMS services.

> Thanks in advance.



Sat, 13 Apr 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to start/stop a NT service

2. Stop and Starting Services on NT

3. Starting and Stopping NT Services with ADSI,wsh, and VBScript

4. Start/Stop a NT Service using wsh/adsi

5. Starting and stopping NT services

6. How to start/stop a NT service...

7. Starting and Stopping NT Services from WSH/VBS

8. Stopping and Starting NT Services

9. Stopping and Starting NT Services

10. Stop/Start NT Services

11. Start/Stop a NT Service using wsh/adsi

12. Starting/Stopping NT Services

 

 
Powered by phpBB® Forum Software