Skip to content

Instantly share code, notes, and snippets.

@robvanoostenrijk
Created April 27, 2015 05:16
Show Gist options
  • Save robvanoostenrijk/fa91a002a67cbfa0f0e3 to your computer and use it in GitHub Desktop.
Save robvanoostenrijk/fa91a002a67cbfa0f0e3 to your computer and use it in GitHub Desktop.
Tridion 2013 Restart Script
Sub StartService(Computer, ServiceName, Wait)
Dim cimv2, oService, Result
' Get the WMI administration object
Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
' Get the service object
Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
' Check base properties
If oService.Started Then
' The service is not started
WScript.Echo now, "The service " & ServiceName & " is started."
Exit Sub
End If
' Start the service
Result = oService.StartService
If 0 <> Result Then
WScript.Echo now, "Start " & ServiceName & " error:" & Result
Exit Sub
End If
Do While InStr(1, oService.State, "running", 1) = 0 And Wait
' Get the current service state
Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
WScript.Echo now, "StartService", ServiceName, oService.Started, oService.State, oService.Status
WScript.Sleep 2000
Loop
End Sub
Sub StopService(Computer, ServiceName, Wait)
Dim cimv2, oService, Result
' Get the WMI administration object
Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
' Get the service object
Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
' Check base properties
If Not oService.Started Then
' The service is Not started
WScript.Echo now, "The service " & ServiceName & " is not started"
Exit Sub
End If
If Not oService.AcceptStop Then
' The service does not accept stop command
WScript.Echo now, "The service " & ServiceName & " does not accept stop command"
Exit Sub
End If
' Stop the service
Result = oService.StopService
If 0 <> Result Then
WScript.Echo now, "Stop " & ServiceName & " error: " & Result
Exit Sub
End If
Do While oService.Started And Wait
' Get the current service state
Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'")
WScript.Echo now, "StopService", ServiceName, oService.Started, oService.State, oService.Status
WScript.Sleep 2000
Loop
End Sub
Sub StopCOMApplication(Computer, ApplicationName)
Dim oCatalog 'As COMAdminCatalog
Set oCatalog = CreateObject("ComAdmin.COMAdminCatalog")
oCatalog.connect(Computer)
WScript.Echo now, "Stopping COM+ " & ApplicationName
oCatalog.ShutdownApplication(ApplicationName)
Set oCatalog = Nothing
End Sub
StopService ".", "TcmPublisher", True
StopService ".", "TcmSearchIndexer", True
StopService ".", "TcmSearchHost", True
StopService ".", "TcmServiceHost", True
StopService ".", "TCDTransportService", True
StopCOMApplication "My Computer", "SDL Tridion Content Manager"
StopCOMApplication "My Computer", "System Application"
' Wait for a key press
WScript.Echo now, "Tridion shutdown complete, press a key for startup"
WScript.StdIn.ReadLine
WScript.Echo now, "Starting Tridion Services"
StartService ".", "TCDTransportService", True
StartService ".", "TcmSearchIndexer", True
StartService ".", "TcmServiceHost", True
StartService ".", "TcmSearchHost", True
StartService ".", "TcmPublisher", True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment