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
| 'ACTIVER/DESACTIVER le service WU sous W10
strComputer = "."
aTargetSvcs = Array("wuauserv") ' Placer ici la liste des services comme par ex.: Array("service1" , "service2" , "service3" , "service-etc")
Set objWMIService = GetObject("winmgmts:" & "{impersonationlevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service")
For Each objService In colServices
For Each sTargetSvc In aTargetSvcs
If LCase(objService.Name) = LCase(sTargetSvc) Then
ServName = UCase(objService.Name)
rep = 0
msgbox objService.State & " " & objService.ChangeStartMode
If objService.State = "Stopped" Then
rep = Msgbox ("Le service Windows " & ServName & " est arrete." &chr(13) &chr(13) & " Voulez-vous l'activer maintenant ?", VbQuestion + vbYesNo + 256, ServName & " (OFF)")
if rep = 7 then ' Non, arret
wscript.quit 0
else ' Oui, l'activer
objService.StartService()
Msgbox "Le service Windows " & ServName & " est actif !", VbCritical + VbOkOnly, ServName & " (ON)"
end if
end if
If objService.State = "Running" Then
rep = Msgbox ("Le service Windows " & ServName & " est actif." &chr(13) &chr(13) & " Voulez-vous le desactiver ?", VbQuestion + vbYesNo + 256, ServName & " (ON)")
if rep = 7 then ' Non, arret
wscript.quit 0
else ' Oui le desactiver
If objService.State = "Running" Then
objService.StopService()
End If
If objService.StartMode <> "Disabled" Then
objService.ChangeStartMode("Disabled")
End If
If objService.State = "Stopped" Then
Msgbox "Le service Windows " & ServName & " est arrete et desactive !", VbCritical + VbOkOnly, ServName & " OFF"
else
Msgbox "Le service Windows " & ServName & " n'a pas pu être arrete !", VbExclamation + VbOkOnly, ServName & " ON"
End if
End If
End If
End If
Next
Next |
Partager