| 12
 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
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 
 |  
Sub ListMachineServices
 
 dim  computer
 
     computer = InputBox("Entrer le nom machine")
 
        Call ServicesList (computer)
 
End Sub
 
 
' ----------------------------------------------------------
' Script VBS d'affichage sous EXCEL de la liste des services
' d'un ordinateur avec nom complet, nom court et état
'
' Syntaxe :
'    ListServ [<ordinateur>]
' Paramètre :
'    <ordinateur> : nom NetBIOS de l'ordinateur
'                   s'il est omis : ordinateur local
'
' Jean-Claude BELLAMY © 2003
' Version améliorée par Jean-Christophe VIALA © 2003
' ----------------------------------------------------------
 
Sub ServicesList (computer)
 
Const xlCenter  = &HFFFFEFF4
Const xlBottom  = &HFFFFEFF5
Const xlContext = &HFFFFEC76
Const msoFalse  = 0
Const msoScaleFromTopLeft = 0
 
Dim ServiceSet, Network,oXL
 Set Network = CreateObject("WScript.Network")
 
 Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & Computer & "/root/cimv2").InstancesOf("Win32_Service")
 
 Set oXL = CreateObject("EXCEL.application")
oXL.Visible = True
oXL.screenupdating=false
oXL.Workbooks.Add
oXL.Cells(1,1).Value ="Services de " & Computer
 
NL=2
 
oXL.Cells(2, 2).Value = "Nom complet "
oXL.Cells(2, 2).Font.ColorIndex = 5
oXL.Cells(2, 3).Value = "Nom court "
oXL.Cells(2, 3).Font.ColorIndex = 5
oXL.Cells(2, 4).Value = "Démarrage "
oXL.Cells(2, 4).Font.ColorIndex = 5
oXL.Cells(2, 5).Value = "État "
oXL.Cells(2, 5).Font.ColorIndex = 5
 
 
' Cellule NL,1,"Nom complet"
' Cellule NL,2,"Nom court"
' Cellule NL,3,"Démarrage"
' Cellule NL,4,"État"
 
 
For each Service in ServiceSet
	NL=NL+1
	oXL.Cells(NL, 2).Value =  Service.Caption
 
	Desc=Service.Description
	If not IsEmpty(Desc) and not IsNull(Desc) and Desc<>Service.Caption Then
		With oXL.Range("A" & NL)
			.AddComment
			.Comment.Visible = True
			.Comment.Text Desc
			.Comment.Shape.Select True
			oXL.Selection.ShapeRange.ScaleWidth 2, msoFalse, msoScaleFromTopLeft
			k=len(Desc)/150
			If k<1 then k=1
			oXL.Selection.ShapeRange.ScaleHeight k, msoFalse, msoScaleFromTopLeft
			oXL.Selection.ShapeRange.SetShapesDefaultProperties
			.Comment.Visible = false
			End With
		End If
	 oXL.Cells(NL, 3).Value =  Service.Name
 
	Select Case Service.StartMode
		Case "Manual"
                        oXL.Cells(NL, 4).Value = "Manuel"
		Case "Disabled"
			oXL.Cells(NL, 4).Value = "Désactivé"
		Case "Auto"
			oXL.Cells(NL, 4).Value = "Automatique"
		Case else
			oXL.Cells(NL, 4).Value = "Problème !"
	end select
 
	Etat=Service.State
	If Lcase(Etat)="running" Then oXL.Cells(NL, 5).Value = "Démarré"
	If NL=int(NL/2)*2 Then
		oXL.Range("A" & NL & ":E" & NL).Select
		oXL.Selection.Interior.ColorIndex = 35
		End If
	Next
oXL.Range("A1").Select
oXL.Selection.Font.Bold = True
With oXL.Selection.Font
	.Name = "Arial"
	.Size = 12
    End With
oXL.Range("A2:E2").Select
oXL.Selection.Font.Bold = True
oXL.Selection.Interior.ColorIndex = 28
 
oXL.Columns("A:E").Select
oXL.Selection.Columns.AutoFit
 
oXL.Columns("C:E").Select
oXL.Selection.HorizontalAlignment = xlCenter
 
oXL.Rows("3:3").Select
oXL.ActiveWindow.FreezePanes = True
 
oXL.Sheets(1).Select
oXL.Sheets(1).Name = "Services"
oXL.DisplayAlerts = False
if oXL.Sheets.count > 1 then
	compteur = oXL.Sheets.count
	for i = compteur to 2 step -1
		oXL.Sheets(i).delete
	next
end if
oXL.cells(1,1).select
oXL.ActiveWorkbook.SaveAs "ListServ-" & Computer & ".xls"
oXL.DisplayAlerts = True
oXL.screenupdating= True
 
 
End Sub | 
Partager