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
| ' Create a new and blank spreadsheet:
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
' Format the cell A1 and add the text: Service
objExcel.Cells(1, 1).Value = "Nom du Service"
objExcel.Cells(1, 1).Font.Bold = TRUE
objExcel.Cells(1, 1).Interior.ColorIndex = 43
objExcel.Cells(1, 1).Font.ColorIndex = 2
' Format the cell A2 and add the text: Status
objExcel.Cells(1, 2).Value = "Etat du service"
objExcel.Cells(1, 2).Font.Bold = TRUE
objExcel.Cells(1, 2).Interior.ColorIndex = 43
objExcel.Cells(1, 2).Font.ColorIndex = 2
'*************************************************
' Format the cell A3 and add the text: Chemin Executable
objExcel.Cells(1, 3).Value = "Chemin Executable"
objExcel.Cells(1, 3).Font.Bold = TRUE
objExcel.Cells(1, 3).Interior.ColorIndex = 43
objExcel.Cells(1, 3).Font.ColorIndex = 2
'*************************************************
' Format the cell A4 and add the text: Description
objExcel.Cells(1, 4).Value = "Description du service"
objExcel.Cells(1, 4).Font.Bold = TRUE
objExcel.Cells(1, 4).Interior.ColorIndex = 43
objExcel.Cells(1, 4).Font.ColorIndex = 2
' Find the Windows services on this computer
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery("Select * From Win32_Service")
' Write each service to Excel, starting in A2
x = 1
For Each objService in colServices
x = x + 1
objExcel.Cells(x, 1) = objService.Name
objExcel.Cells(x, 2) = objService.State
objExcel.Cells(x, 3) = objService.PathName
objExcel.Cells(x, 4) = objService.Description
Etat = objService.Started
If Etat Then
Cellule x,2,"Démarré"
ELSE
Cellule X,2,"Arrêté"
objExcel.Cells(x, 2).Font.ColorIndex = 3
objExcel.Cells(x, 3).Font.ColorIndex = 3
objExcel.Cells(x, 4).Font.ColorIndex = 3
end if
Next
' Autofit the first column to fit the longest service name
objExcel.Columns("A:A").EntireColumn.AutoFit
objExcel.Columns("B:B").EntireColumn.AutoFit
objExcel.Columns("C:C").EntireColumn.AutoFit
objExcel.Columns("D:D").EntireColumn.AutoFit
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Set Network = WScript.CreateObject("WScript.Network")
Computer = Network.ComputerName
objExcel.ActiveWorkbook.SaveAs fso.GetAbsolutePathName(".") & "\Liste-Services_" & Computer & ".xls"
objExcel.DisplayAlerts = True
'--------------------------------------------------------------------
Sub Cellule(X,NC,chaine)
objExcel.Cells(X,NC).Value = Chaine
End Sub
'-------------------------------------------------------------------- |
Partager