Créer un template : Tmp_service_Auto_Restart
Dans le template créer l’Item
Item : Service_Automatic_Restart
Dans la clé Key, mettre
services[automatic, stopped, "gupdate,RemoteRegistry,SysmonLog,CIMnotify,sppsvc,clr_optimization_v4.0.30319_64,clr_optimization_v4.0.30319_32"]
Liste des services non concerné entre « » séparé par ,
Créer un trigger sur l’item
Trigger : TRG_services_automatic_stopped
Créer une Action (Configuration Action)
Action: TRG_services_automatic_stopped
Créer une opération (onglet opération)
Ajouter une étape (New step, bon sur l’exemple elle existe déjà)
Ne pas oublier Update à la fin de la création de l’étape.
Et Update de l’ACTION.
Sur les serveurs windows :
Voici les scripts à mettre sur les serveurs sur lesquels on veut redémarrer automatiquement les services qui tombent.
Il faut créer un dossier c:\temp\
c:\Batchs\Start_service_auto.bat
@echo off
cls
:: EF le 16/05/2012
:: MV le 17/01/2017 ajout du check for permissions, windows 2012 r2
setlocal enableDelayedExpansion
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
set fic_log=c:\temp\service_to_restart.log
set fic_temp=c:\temp\service_to_restart.txt
set fic_start=c:\temp\service_to_start.txt
set fic_bat=c:\temp\service_to_start.bat
del /F %fic_log%
del /F %fic_temp%
del /F %fic_start%
del /F %fic_bat%
TIMEOUT /T 3 /NOBREAK 1>nul
TYPE NUL > %fic_start%
TYPE NUL > %fic_bat%
wmic service where (state="stopped" and startmode="Auto") get name>%fic_temp%
for /f "delims= skip=1" %%i in ('type %fic_temp%') do (
set w_serv=%%i
echo net start %%i>> %fic_start%
)
TIMEOUT /T 3 /NOBREAK 1>nul
for /f "tokens=1,2,3* delims= " %%i in (%fic_start%) do (
set wstr=%%i %%j
set wser=%%k %%l
for /l %%a in (11,1,100) do if "!wser:~-1!"==" " set wser=!wser:~0,-1!
set w_ligne=!wstr!"!wser!"
echo !w_ligne!
echo !w_ligne!>>%fic_bat%
echo TIMEOUT /T 5 /NOBREAK >> %fic_bat%
)
%fic_bat% > %fic_log%
c:\Batchs\test.bat
@echo off
echo TEST > c:\temp\test.txt
echo %1 >> c:\temp\test.txt