1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| Dim ETAT_SERVICE
Dim WIN_SERVICE1
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
Function getSystemVar(VarName)
Dim wss, env
Set wss = CreateObject("WScript.Shell")
Set env = wss.environment("process")
getSystemVar = env(VarName)
End Function
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, intSleep
strComputer = "."
intSleep = 5000
Set args = Wscript.Arguments
ETAT_SERVICE = args(0)
WIN_SERVICE1 = args(1)
message = "The service" & (WIN_SERVICE1) & "is in state :" & (ETAT_SERVICE)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ="_
& WIN_SERVICE1 & " ")
For Each objService in colListOfServices
If (ETAT_SERVICE) <> "Startservice" and (ETAT_SERVICE) <> "Stopservice" Then
parametre = "Parametre Invalide"
If Err.Number = 0 Then 'Fichier Log n'existe pas
Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log")
Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
FtxtBis.writeline (parametre)
FtxtBis.Close
Set FtxtBis = Nothing
Ftxt.Close
Set Ftxt = Nothing
Else 'Fichier log existe
Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log")
Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
FtxtBis.writeline (parametre)
FtxtBis.Close 'Fermeture
Set FtxtBis = Nothing
Ftxt.Close
Set Ftxt = Nothing
End If
FSO.Close
end if
If (ETAT_SERVICE) = "Startservice" Then
return = objService.StartService(WIN_SERVICE1)
if Return = 5 then
Return = 0
else
if Return = 10 then
Return = 0
end if
end if
Else If (ETAT_SERVICE) = "Stopservice" Then
return = objService.StopService(WIN_SERVICE1)
if Return = 5 then
Return = 0
else
if Return = 10 then
Return = 0
end if
end if
End If
End If
WSCript.Sleep intSleep
Next
If Err.Number = 0 Then 'Fichier Log n'existe pas
Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log")
Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
FtxtBis.writeline (Year(date)) & vbTab & (Month(date)) & vbTab & (Day(date)) & vbTab & (time) & vbTab & (getSystemVar("COMPUTERNAME")) & vbTab & resultat1 & vbTab & resultat2 & vbTab & (PID) & vbTab & (terminal) & vbTab & resultat5 & vbTab & resultat4 & vbTab & return & vbTab & (gravite) & vbTab & resultat3 & vbTab & (getSystemVar("UNISON_JOBNUM")) & vbTab & (valeur) & vbTab &(parametre) & vbTab & (message)
FtxtBis.Close
Set FtxtBis = Nothing
Ftxt.Close
Set Ftxt = Nothing
Else 'Fichier log existe
Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log")
Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
FtxtBis.writeline (Year(date)) & vbTab & (Month(date)) & vbTab & (Day(date)) & vbTab & (time) & vbTab & (getSystemVar("COMPUTERNAME")) & vbTab & resultat1 & vbTab & resultat2 & vbTab & (PID) & vbTab & (terminal) & vbTab & resultat5 & vbTab & resultat4 & vbTab & return & vbTab & (gravite) & vbTab & resultat3 & vbTab & (getSystemVar("UNISON_JOBNUM")) & vbTab & (valeur) & vbTab &(parametre)& vbTab & (message)
FtxtBis.Close 'Fermeture
Set FtxtBis = Nothing
Ftxt.Close
Set Ftxt = Nothing
End If
FSO.Close |