Changement de statut des services windows
Bonjour à tous,
Je dois par un script 1 modifier le statut de plusieurs services les passer de Disable en Enable, puis les démarrer.
Par un script 2 faire l'inverse :
Stopper les services, puis les passer de Enable en Disable.
J'ai trouvé ceci pour un service (exp. SSIE), ça ne fonctionne pas alors pour plusieurs ???
Merci pour votre aide.
Script:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name ='SSIE'")
For Each objService in colServiceList
If objService.State = "Running" Then
objService.StopService()
Wscript.Sleep 5000
End If
errReturnCode = objService.ChangeStartMode("Disabled")
Next |
Toujous un petit soucis ?
Merci pour ta réponse Cachlab,
mais lorsque j' exécute le script avec tes modifications, il ne traite que le premier service ? (SSIE) il le passe bien en manuel, et le démarre (service désactivé et arrêté avant l’exécution du script)
j'ai donc toujours mon pb, merci pour ton aide.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Function StrInArr(strIn, arrIn)
Dim strTmp, boolOut
boolOut = False
For Each strTmp In arrIn
If StrComp(strTmp, strIn, vbTextCompare) = 0 Then boolOut = True
Next
StrInArr = boolOut
End Function
Dim arrServices
strComputer = "."
arrServices = Array("SSIE", "Telnet") 'Saisir ici la liste des services
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where StartMode = 'Disabled'") ' On sélectionne les services désactivés
For Each objService in colServiceList
If StrInArr(objservice.Name, arrServices) then ' On vérifie s'ils sont dans la liste arrServices
objservice.ChangeStartMode("Manual") ' Si oui on les passe en démarrage Manuel
'if objService.state = "Stopped" Then objService.StartService() ' Et s'ils sont arrêtés, on les démarre
End if
Next |
Cordialement
PAB
Merci pour vos réponses, mais j'ai un gros problème
Merci Cachlab et Cubitus,
mais je ne m'en sors pas ?
je m'explique:
Mes deux services "SSIE" et "Telnet" sont désactivés et arrêtés.
Lorsque je lance le script (celui de Cachlab) il ne se passe rien ?
J'ajoute la modif (cubitus) toujours rien. Mes services restent
désactivés et arrêtés.
Là je souffre... Merci pour vos aides.
Pab
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Function StrInArr(strIn, arrIn)
Dim strTmp, boolOut
boolOut = False
For Each strTmp In arrIn
If StrComp(strTmp, strIn, vbTextCompare) = 0 Then boolOut = True
Next
StrInArr = boolOut
End Function
Dim arrServices
strComputer = "."
arrServices = Array("SSIE", "Telnet") 'Saisir ici la liste des services
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where StartMode = 'Disabled'") ' On sélectionne les services désactivés
For Each objService in colServiceList
If StrInArr(objservice.Name, arrServices) then ' On vérifie s'ils sont dans la liste arrServices
objservice.ChangeStartMode("Manual") ' Si oui on les passe en démarrage Manuel
'if objService.state = "Stopped" Then objService.StartService() ' Et s'ils sont arrêtés, on les démarre
End if
Next |