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
| Dim SRVC, ObjServ, myObj,Ret,nRet,cnt,n,fso,fich,wshshell,svName
Function Espace(strName)
dim strRet,Complement,Count
If Len(strName)<=25 Then
strRet=strName
complement=Mid(strName,1,25-Len(strName))
Else
strRet=Mid(StrName,1,24)+"_" +vbCrlf + Mid(strName,25,Len(strName))
Complement=Mid(strName,25,Len(strName))
End If
'Count=IIf(Len(strName)<=24,25-Len(strName),25-Len(Complement))
If Len(strName)<=24 then
Count=25-Len(strName)
Else
Count=25-Len(Complement)
End IF
Espace = String(count," ")
End Function
'=============================================
' La fonction suivante sert à couper le nom du service en 2 parties s'il fait
' plus de 25 caractères: Elle ajoute aux 24 premiers caractères le symbole "_" puis
' un retour chariot et ajoute le reste du nom suivi de son nom d'affichage
'=============================================
Function Diviser(strName)
dim strRet
If Len(strName)<=25 Then
strRet=strName
Else
strRet=Mid(StrName,1,24)+"_" +vbCrlf + Mid(strName,25,Len(strName))
End If
Diviser=strRet
End Function
Set SRVC = GetObject("winmgmts:\\")
Set ObjServ = SRVC.InstancesOf("Win32_Service")
Set wshshell = CreateObject("Wscript.Shell")
' ============================
' Les 6 lignes suivantes et la fonction "Espace" servent à formater le texte
' de sortie pour une meilleure lisibilité.
'=============================
svName=ucase(" Nom du service"+Espace(" Nom du service")+" Nom d'affichage")+VbCrlf
Ret=String(20," ") + ucase("Auto_Running Services")+vbcrlf
Ret=Ret + String(60,"=") + Vbcrlf +svName+VbCrlf
nRet=String(60,"=")+vbcrlf
nRet=nRet + String(20," ") + Ucase("Not Auto_running services")+vbcrlf
nRet=nRet + String(60,"=") +vbcrlf +svName+VbCrlf
' ========== Fin du formatage du texte =============
Set fso = Wscript.CreateObject("Scripting.FilesystemObject")
set fich = fso.CreateTextFile("C:\Services.txt",true)
fich.writeblanklines 1
cnt=0 :n=0
For Each myObj In ObjServ
If Ucase(myObj.StartMode) = "AUTO" Then
If ucase(myObj.State) = "RUNNING" Then
Ret= Ret & Diviser(Ucase(myObj.Name)) & Espace(myObj.Name) + " : " & myObj.DisplayName & Vbcrlf
n=n+1
End If
ElseIF ucase(myObj.StartMode) <> "AUTO" Then
nRet= nRet + Diviser(Ucase(myObj.Name)) & Espace(myObj.Name) +" : " & myObj.DisplayName & Vbcrlf
cnt=cnt+1
End If
Next
Fich.Write Ret + vbcrlf+"Nombre de Services démarrés auto : "+cstr(n)+vbcrlf
fich.WriteBlankLines 1
Fich.Write nRet+ vbcrlf+"Nombre de Services démarrés non auto : "+cstr(cnt)
wshshell.Run "Notepad.exe C:\Services.txt",1,True
Set wshshell = Nothing
Set Fso=Nothing
Set Srvc=Nothing |
Partager