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 45 46 47 48 49 50 51 52
|
Const SHUTDOWN = 1
Const LOGOFF = 0
Const Reboot = 2
Const ForcedLogoff = 4
Const ForcedShutdown = 5
Const ForcedReboot = 6
Const PowerOff = 8
Const ForcedPowerOff = 12
' Demande à l'usager l'ordinateur à traiter
' -----------------------------------------
Ordinateur = inputbox ("Indiquez l'ordinateur.","Logoff d'un usager sur un ordinateur")
Ordinateur = trim(lcase(Ordinateur))
if left(Ordinateur,2) = "\\" then Ordinateur = mid(Ordinateur,3,10)
if Ordinateur = "" or Ordinateur = "." then
wscript.echo "Pas d'ordinateur indiqué." & vbCrLf & "Pas de logoff possible."
WScript.Quit
end if
' Demande une confirmation
' ------------------------
reponse = msgbox("Voulez-vous vraiment faire un LOGOFF sur le pc?", vbYesNo, "LOGOFF UN PC")
if reponse <> 6 then
WScript.Quit
end if
' Vérifie si l'ordinateur est on-line
' -----------------------------------
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_PingStatus " & "Where Address = '" & Ordinateur & "'")
For Each objItem in colItems
If objItem.StatusCode = 0 Then
else
Wscript.Echo "PC non disponible."
WScript.Quit
End If
Next
' Logoff l'usager qui est dessus le PC.
' -------------------------------------
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & Ordinateur & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(ForcedLogoff)
Next
msgbox "Commande de logoff envoyée à " & ucase(ordinateur) |
Partager