How to start/stop a NT service... 
Author Message
 How to start/stop a NT service...

Hi,

I wonder if it is possible to start and stop a NT service via WSH?
Has somebody experience with this topic?

Thanks in advance for your help,

Thomas Eiberle



Tue, 22 Oct 2002 03:00:00 GMT  
 How to start/stop a NT service...
There's an example using ADSI in the ADSI FAQ.  There's also an example using WMI in the WMI FAQ.

Win32 Scripting [Clarence Washington]
http://cwashington.netreach.net
http://cwashington.netreach.net/script_repository/repository.asp
http://cwashington.netreach.net/script_repository/query.asp
http://cwashington.netreach.net/main_site/downloads

Go here:
http://cwashington.netreach.net/script_repository/faqs.asp?topic=wmifaq

Go here:
http://cwashington.netreach.net/script_repository/faqs.asp?topic=adsifaq

--
Michael Harris
MVP Scripting


Hi,

I wonder if it is possible to start and stop a NT service via WSH?
Has somebody experience with this topic?

Thanks in advance for your help,

Thomas Eiberle



Tue, 22 Oct 2002 03:00:00 GMT  
 How to start/stop a NT service...
Here is a sample I just wrote for one of my MS Press WSH books.
The sample requires ADSI installed.

'************************************************
' File:   StartStopService.vbs (WSH-sample in VBScript)
' Author: (c) G. Born
'
' Demonstrates how to start and stop a service using
' ADSI. (A sample from my MS Press book Advanced
' Windows Script Host Programming)
'************************************************
Option Explicit

Const service = "cisvc"           ' Indexing service
Const computer = "Rom"
Dim oService, oComp
Dim sState

sState = array ("", "stopped", "start pending", "stop pending", _
               "running", "continue pending", "pause pending", _
               "paused", "error")

' Bind to service object
Set oComp = GetObject("WinNT://" & computer & ",computer")

Set oService = oComp.GetObject ("Service", service)

' attempt to start service
If MsgBox ("Service '" & service & "' status is: " & _
           sState(oService.Status), vbYesNo + vbQuestion, _
           "Start service on Computer //" & computer& "?") _
           = vbYes Then
    oService.start                 ' start my service
    WScript.Echo "Service started" ' delay ...
End if

' attempt to pause service
If MsgBox ("Service '" & service & "' status is: " & _
           sState(oService.Status), vbYesNo + vbQuestion, _
           "Pause service on Computer //" & computer& "?") _
           = vbYes Then
    oService.pause                 ' pause service
    WScript.Echo "Service paused"  ' delay ...
End if

' attempt to stop service
If MsgBox ("Service '" & service & "' status is: " & _
           sState(oService.Status), vbYesNo + vbQuestion, _
           "Stop service on Computer //" & computer& "?") _
           = vbYes Then
    oService.stop                  ' stop service
    WScript.Echo "Service stopped" ' delay ...
End if

WScript.Echo "Service '" & service & " Status '" & _
     sState(oService.Status) & "' on Computer //" & computer

Set oService = Nothing         ' release object variable

WScript.Quit
'*** End

--
______________________________________________________
Check out the WSH Bazaar at www.borncity.de

Thomas Eiberle schrieb in Nachricht

Quote:
>Hi,

>I wonder if it is possible to start and stop a NT service via WSH?
>Has somebody experience with this topic?

>Thanks in advance for your help,

>Thomas Eiberle



Tue, 22 Oct 2002 03:00:00 GMT  
 How to start/stop a NT service...
Isn't that a bit of overkill?  A one-line batch file can start or stop a
service.
-- DE
Quote:

> Hi,

> I wonder if it is possible to start and stop a NT service via WSH?
> Has somebody experience with this topic?

> Thanks in advance for your help,

> Thomas Eiberle



Thu, 24 Oct 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. Script To Stop/Start 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