' ---------------------------------------------------------- ' Script VBS d'affichage sous EXCEL de la liste des services ' d'un ordinateur avec nom complet, nom court et état ' ' Syntaxe : ' ListServ [] ' Paramètre : ' : nom NetBIOS de l'ordinateur ' s'il est omis : ordinateur local ' ' Jean-Claude BELLAMY © 2003 ' Version améliorée par Jean-Christophe VIALA © 2003 ' ---------------------------------------------------------- Const xlCenter = &HFFFFEFF4 Const xlTop = &HFFFFEFC0 Const xlBottom = &HFFFFEFF5 Const xlContext = &HFFFFEC76 Const msoFalse = 0 Const msoScaleFromTopLeft = 0 Dim Args, Computer, ServiceSet, Network,oXL,Shell Set Network = WScript.CreateObject("WScript.Network") Set Args = WScript.Arguments Set Shell=Wscript.CreateObject("WScript.Shell") nbargs=args.count If testarg("?") or testarg("h") Then Syntaxe If nbargs > 0 Then Computer = UCase(Args(0)) else Computer = Network.ComputerName Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & Computer & "/root/cimv2").InstancesOf("Win32_Service") Set WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & Computer & "/root/cimv2") WScript.Echo Set oXL = WScript.CreateObject("EXCEL.application") oXL.Visible = True oXL.screenupdating=true oXL.Workbooks.Add oXL.Cells.Select With oXL.Selection.Font .Name = "Tahoma" .Size = 8 End With oXL.Cells(1,1).Value ="Liste des services de l'ordinateur " & Computer oXL.Range("A1").Select With oXL.Selection.Font .Bold = True .Size = 12 End With NL=2 Cellule NL,1,"Nom complet" Cellule NL,2,"Nom court" Cellule NL,3,"Démarrage" Cellule NL,4,"État" Cellule NL,5,"Exécutable" Cellule NL,6,"Interaction avec" & VBLF & "le bureau" Cellule NL,7, "Ce service dépend de :" Cellule NL,8, "Dépendants de ce service :" oXL.Range("A2:H2").Select oXL.Selection.Font.Bold = True oXL.Selection.Interior.ColorIndex = 28 shell.Popup "Veuillez patienter ..." & VBCRLF & "Le tableau va se remplir en arrière-plan", _ 3, "Liste des services de " & Computer, vbInformation oXL.screenupdating=false For each Service in ServiceSet NL=NL+1 Cellule NL,1,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 Cellule NL,2,Service.Name Select Case Service.StartMode Case "Manual" Cellule NL,3,"Manuel" Case "Disabled" Cellule NL,3,"Désactivé" Case "Auto" Cellule NL,3,"Automatique" Case else Cellule NL,3,"Problème !" end select Etat=Service.Started If Etat Then Cellule NL,4,"Démarré" else Cellule NL,4,"Arrêté" Cellule NL,5,Service.PathName Interact=Service.DesktopInteract If Interact Then Cellule NL,6,"OUI" else Cellule NL,6,"NON" Set colServiceList = WMIService.ExecQuery("Associators Of {Win32_Service.Name='" _ & Service.Name & "'} Where AssocClass=Win32_DependentService Role=Dependent") DepList="" For Each objService in colServiceList If DepList<>"" Then DepList=DepList & vbLf DepList=DepList & objService.DisplayName next Cellule NL,7,DepList Set colServiceList = WMIService.ExecQuery("Associators Of {Win32_Service.Name='" _ & Service.Name & "'} Where AssocClass=Win32_DependentService Role=Antecedent") AntList="" For Each objService in colServiceList If AntList<>"" Then AntList=AntList & vbLf AntList=AntList & objService.DisplayName next Cellule NL,8,AntList If NL=int(NL/2)*2 Then oXL.Range("A" & NL & ":H" & NL).Select oXL.Selection.Interior.ColorIndex = 35 End If Next oXL.screenupdating= True oXL.Columns("A:H").Select oXL.Selection.Columns.AutoFit oXL.Selection.VerticalAlignment = xlTop oXL.Columns("C:D").Select oXL.Selection.HorizontalAlignment = xlCenter oXL.Range("B3").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 '-------------------------------------------------------------------- Sub Cellule(NL,NC,chaine) oXL.Cells(NL,NC).Value = Chaine End Sub '-------------------------------------------------------------------- Sub Syntaxe msg=VBCRLF msg=msg & "Script VBS d'affichage sous EXCEL de la liste des services d'un ordinateur" & VBCRLF msg=msg & "avec nom complet, nom court, démarrage, état, dépendances de chaque service." & VBCRLF & VBCRLF msg=msg & "Jean-Claude BELLAMY © 2005" & VBCRLF msg=msg & "Contribution de Jean-Christophe VIALA © 2003" & VBCRLF msg=msg & "--------------------------------------------" & VBCRLF msg=msg & " Syntaxe :" & VBCRLF msg=msg & " ListServ []" & VBCRLF msg=msg & " Paramètre :" & VBCRLF msg=msg & " : nom NetBIOS de l'ordinateur" & VBCRLF msg=msg & " s'il est omis : ordinateur local" & VBCRLF wscript.echo msg wscript.quit End Sub '-------------------------------------------------------------------- Function testarg(param) testarg=false For i = 0 To nbargs-1 curarg=lcase(args(i)) If left(curarg,1)="/" or left(curarg,1)="-" Then If mid(curarg,2,len(param))=param Then testarg=true exit function End If End If Next End Function '--------------------------------------------------------------------