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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| Const ForReading = 1, ForWriting = 8
Dim oFSO, oSh, WSHShell, Rep_Courant
Set oSh = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = CreateObject("WScript.Shell")
set wshnetwork = createobject("wscript.network")
Public StrComputer, onlinestate
date_heure = now
Rep_Courant = WScript.ScriptFullName
Rep_Courant = left(Rep_Courant,InStrRev(Rep_Courant,"\"))
Admin = "Admin"
wuser=lcase(wshnetwork.username)
' ******************************
' Variables à modifier si besoin
' ******************************
Liste_Pc = "LISTE_PC.txt"
Fichier_tmp = "LISTE_TMP.txt"
Fichier_Rapport = "RAPPORT_RESTART.txt"
on error resume next
' **************************************
' Test Fichier_pc_txt existe et non-vide
' **************************************
If oFSO.FileExists(Liste_Pc) = False Then MsgBox"Liste des postes non-trouvée :" & VbCrLf & Liste_Pc & VbCrLf & VbCrLf & "FIN DU SCRIPT", vbOkOnly : Wscript.Quit
Set oFl = oFSO.GetFile(Liste_Pc)
If oFl.Size = 0 Then MsgBox"Aucun poste dans la liste :" & VbCrLf & Liste_Pc & VbCrLf & VbCrLf & "FIN DU SCRIPT", vbOkOnly : Wscript.Quit
If oFSO.FileExists(Fichier_Rapport) Then oFSO.DeleteFile Fichier_Rapport, True
' **************************
' Vérification compte Administrateur
' **************************
set reload = 0
if wuser <> lcase(Admin) Then reload = Msgbox("Vous devez utiliser la session " & Admin & " !" & VbCrLf & VbCrLf & "Voulez-vous fermer la session actuelle ?", vbYesNo,
"Fermer Session")
if reload = 6 then WSHShell.Run "C:\WINDOWS\system32\shutdown.exe -l -t 0" : Wscript.Quit
if reload = 7 then Wscript.Quit
' **************************************
' Confirmation de démarrage du programme
' **************************************
set reload = 0
reload = Msgbox("Attention cette procédure ignore les sessions en cours." & VbCrLf & VbCrLf & "Voulez-vous lancer le redémarrage ?", vbYesNo, "Confirmation")
if reload = 7 then Wscript.Quit
' ******************************
' Ecriture du fichier temporaire
' ******************************
Set Var_tmp = oFSO.CreateTextFile(Fichier_tmp) : Var_tmp.close
Set lect = oFSO.OpenTextFile(Liste_Pc, ForReading)
Set ecr = oFSO.OpenTextFile(Fichier_tmp, ForWriting)
While Not lect.AtEndOfStream
Texte = lect.ReadLine
Texte = Trim(Texte)
If len(Texte) > 0 Then
ecr.WriteLine Texte
End if
Wend
lect.close
ecr.close
' *******************
' Ajout date et heure
' *******************
If oFso.FileExists(Fichier_Rapport) = False then oFso.CreateTextFile(Fichier_Rapport)
set myfile = oFso.OpenTextFile(Fichier_Rapport, ForWriting) : myfile.Write("Reboot des postes : " & date_heure & vbNewLine & vbNewLine) : myfile.Close
' ********************
' Lecture liste postes
' ********************
Set f = oFSO.OpenTextFile(Fichier_tmp, ForReading)
ts = f.ReadAll
nbr_pc = f.Line
f.close
Set f = oFso.OpenTextFile(Fichier_tmp, ForReading)
Dim pc()
Redim pc(nbr_pc,2)
i = 1
Do While Not f.AtEndOfStream
pc(i,1) = f.Readline
i = i + 1
Loop
f.close
If oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
if pc(nbr_pc,1) = "" Then nbr_pc = nbr_pc - 1
' *****************
' Reboot des postes
' *****************
For i = 1 to nbr_pc
StrComputer = pc(i,1)
Call online
if pc(i,2) = 1 Then
set myfile = oFso.OpenTextFile(Fichier_Rapport, ForWriting) : myfile.Write(pc(i,1) & " : Reboot demandé" & vbNewLine) : myfile.Close
WSHShell.Run ("C:\WINDOWS\system32\shutdown.exe -m \\" & pc(i,1) & " -r -t 0") : WScript.Sleep(1000)
Else
set myfile = oFso.OpenTextFile(Fichier_Rapport, ForWriting) : myfile.Write(pc(i,1) & " : *** Inaccessible ***" & vbNewLine) : myfile.Close
End if
Next
' *************
' Fin du script
' *************
set myfile = oFso.OpenTextFile(Fichier_Rapport, ForWriting) : myfile.Write(vbNewLine & "________________________________________" & vbNewLine & vbNewLine) :
myfile.Close
oExec.Terminate
WSHShell.Run ("C:\WINDOWS\system32\notepad.exe " & Fichier_Rapport)
WScript.Quit
' *********************
' Sous fonction ping PC
' *********************
Sub online
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("select * from Win32_PingStatus where address = '" & StrComputer & "'")
For Each objStatus in objPing
If objStatus.Statuscode = 0 Then pc(i,2) = 1 else pc(i,2) = 0
Next
End Sub |