-2

We have a Windows 2012 R2 with some services configured as delayed start due to having dependencies on other services, but not being shown in the corresponding tab. If such services are not configured that way, they fail to start.

Since the server is powered up only during business hours we want to send a mail when all services are up and running but no such trigger exists in task scheduler.

A tasks was scheduled "when system starts" but obviously it does not work as desired.

How can this be accomplished? Is there a way to add a dependency on a service?

1 Answer 1

0

Not exactly what was needed but running this script when systems starts does the job

' VB Script Document
option explicit
Const MAIL_SERVICE = "mail_service"
Const VCS_SERVICE  = "our_vcs_service"

Dim args,status,objShell
Set args = Wscript.Arguments
' esperar el correo
status = wait_service (MAIL_SERVICE,10,6)
If (status = 0) Then
 ' esperar el control de versiones
 status = wait_service (VCS_SERVICE,10,6)
 Do While (status <> 0)
   status = wait_service (VCS_SERVICE,10,6) 
 Loop
End If

If (status = 0) Then
 Set objShell = CreateObject("WScript.Shell") 
 objShell.Run "sendEMail.exe ..." 
End If


Function wait_service (service_name,seconds,retries)
 Dim svcs 
 
 seconds = 1000*seconds

 ' no funciona
 wait_service = 1
 svcs = service_status (service_name)
 If (svcs = 1) Then
   Exit Function
 End If 
 
 ' iterar, esperando los segundos indicados 
 Do While (svcs <> 0) And (retries <> 0)
   retries = retries - 1
   WScript.Sleep seconds
   svcs = service_status (service_name) 
 Loop
 
 wait_service = svcs 
End Function

 
Function service_status (service_name)
 Dim wmi
 Dim svcs,svc
 ' no existe
 service_status = 1
 
 Set wmi = GetObject("winmgmts:\\.\root\cimv2")
 Set svcs = wmi.ExecQuery("Select * from Win32_Service where Name = '" & service_name & "'")
 If (svcs.Count = 0) Then
   Exit Function
 Else  
   ' no está ejecutando
   service_status = 2
   ' https://stackoverflow.com/questions/2378723/get-first-record-from-wmi-execquery'
   Set svc = svcs.ItemIndex(0)
   If (svc.State = "Running") Then
     service_status = 0
   End If
 End If
End Function  

The script waits for the mail server to be up and running and then also waits for the VCS server. If both are running the mail is sent

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .