Bonjour,

Apres avoir parcouru le forum je n'ai pas trouvé mon bonheur c'est pour ca que je me permets de vous demander de ma mettre soit sur la piste soit comment le faire. Je voudrais tester si un service est deja démarré. Si celui -ci est demarré alors il me renvoie une erreur sinon il effetue la commande passé.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
'Fonction remontant le service et son etat
 
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, intSleep
strComputer = "."
intSleep = 5000
 
' NB strService is case sensitive.
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" Then
  return = objService.StartService(WIN_SERVICE1)
  Else If (ETAT_SERVICE) = "Stopservice" Then
   return = objService.StopService(WIN_SERVICE1)
 End If
End If
Merci pour votre aide