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