' Name: StartStopServices
' Author: Egil Hansen - www.egil.dk
' Date: 2007.03.18
' Description: This script can be used to start/stop a number
' of services and their dependtents, in a toggle
' start/stop fashion.
' It also allows you to specify a explicit action,
' either start or stop.
'
' Usage: Simply add the services to the array arrServices below,
' in the order you want the services to be stopped/started.
'
Option Explicit
' Add services
Dim arrServices(2)
arrServices(0) = "IISADMIN"
arrServices(1) = "MSSQLSERVER"
arrServices(2) = "msftesql"
' Declare variables
Dim strService, objIntExplorer
' Look for explicit requests from user
If ExplicitStartStop() => 0 Then
' Start IE window
Set objIntExplorer = Wscript.CreateObject("InternetExplorer.Application")
Call SetupIE(objIntExplorer)
Select Case ExplicitStartStop()
Case 0
' Iterate over each service, decide what to do based on their current status
For Each strService in arrServices
If IsServiceRunning(strService) Then
StopServiceAndDependents(strService)
Else
StartServiceAndDependents(strService)
End If
Next
Case 1
' Iterate over each service and stop them
For Each strService in arrServices
StopServiceAndDependents(strService)
Next
Case 2
' Iterate over each service and start them
For Each strService in arrServices
StartServiceAndDependents(strService)
Next
End Select
' Close IE window
Call CloseIE(objIntExplorer)
End If
' Exit
Wscript.Quit(0)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' End of main script section, helper functions below
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub PrintLn(str)
On Error Resume Next
objIntExplorer.Document.WriteLn (str & "
")
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Set up Internet Explorer for use as a status message window
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub SetupIE(objIntExplorer)
Dim strTitle
strTitle = "Start/Stop services scriptt"
' Create reference to objIntExplorer
' This will be used for the user messages. Also set IE display attributes
With objIntExplorer
.Navigate "about:blank"
.ToolBar = 0
.Menubar = 0
.StatusBar = 0
.Width = 500
.Height = 250
.Left = 50
.Top = 20
End With
' Set some formating
With objIntExplorer.Document
.WriteLn ("")
.WriteLn ("