Shutdown si Pc non utilisé
Bonjour,
J'ai un script qui permet d'eteindre mes postes si personne n'est connectée dessus.
Je lance le script via un run as pour être connecté en admin du domain car je me connecte à distance.
Le script fonctionne parfaitement sous un environnement XP mais malheureusement, il ne fonctionne pas sous Windows 7.
Le script bloque au niveau "Set objWMIService" mais je ne trouve pas de solution :(
Pouvez-vous m'aider ?
Voici le script :
Code:
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
|
Dim strHost, objWMIService, objComputer, colComputer, colOperatingSystems, objOperatingSystem
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Ftxt = FSO.OpenTextFile("c:\Utilitaire\strhost.txt")
Do While Not Ftxt.AtEndOfStream
strhost = Ftxt.Readline
Loop
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strhost & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
if isNull(objComputer.UserName) or objComputer.UserName = "" then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strhost & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
'ObjOperatingSystem.Reboot()
Next
msgbox ("Le redémarrage de " & strHost & " est en cours")
else
msgbox("Redémarrage impossible " & objComputer.UserName & " est logué")
end if
Next |