IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Transformation d'un programme DOS en VBScript pour reboot de 1 ou plusieurs micro


Sujet :

VBScript

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 28
    Points : 26
    Points
    26
    Par défaut Transformation d'un programme DOS en VBScript pour reboot de 1 ou plusieurs micro
    Bonjour à tous,

    Je suis très novice en VBS et je cherche à me faciliter la tache pour rebooter des ordinateurs de mon réseau.
    Actuellement j'utilise ce script sous DOS:

    wmic /node:nom de l'ordinateur /user:"DomaineAD\Compte Administrateur" /password:"mot_de_passe du compte Admin" os where primary=true call reboot

    Ce que je voudrais faire:

    Au lancement du script une ou 2 boites de dialogue qui demande le compte administrateur puis le mot de passe de ce même compte, lecture d'un fichier texte ou j'aurais la liste des postes (1 par ligne ) à redémarrer, et donc l’exécution de la commande de reboot pour chaque ligne de poste.
    J’espère avoir été clair et si quelqu'un peut m'aider ce serait très sympa.
    Merci

    PS : J’espère avoir mis cette demande au bon endroit

  2. #2
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut

    Je crois qu'il est plus commode d'utiliser un Tableau au lieu de les lire dans un fichier, donc à modifier cette partie du script Par les noms de vos ordinateurs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    'Liste des Ordinateurs à Rebooter
    ComputerName = array("Ordinateur1","Ordinateur2","Ordinateur3","Ordinateur4","Ordinateur5","Ordinateur6","Ordinateur7","Ordinateur8","Ordinateur9",_
    "Ordinateur10")
    Donc à tester ce script puis commentez ou bien Supprimez les MsgBox de tests:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
        Dim objIE,WS
    	'Liste des Ordinateurs à Rebooter
    	ComputerName = array("Ordinateur1","Ordinateur2","Ordinateur3","Ordinateur4","Ordinateur5","Ordinateur6","Ordinateur7","Ordinateur8","Ordinateur9",_
    "Ordinateur10")
    	Set WS = CreateObject("Wscript.Shell")
        Set objIE = CreateObject( "InternetExplorer.Application" )
        objIE.Navigate "about:blank"
        objIE.Document.Title = "Reboot à Distance " & String( 200, "*" )
        objIE.ToolBar        = False
        objIE.Resizable      = False
        objIE.StatusBar      = False
        objIE.Width          = 320
        objIE.Height         = 220
        With objIE.Document.ParentWindow.Screen
            objIE.Left = (.AvailWidth  - objIE.Width ) \ 2
            objIE.Top  = (.Availheight - objIE.Height) \ 2
        End With
        Do While objIE.Busy
            WScript.Sleep 200
        Loop
        objIE.Document.Body.InnerHTML = "<div align=""center""><p>Nom Utilisateur " _
    	                              & "<br><input type=""text"" size=""20"" " _
    								  & "id=""Login"" value=""Administrateur""></p>"_
                                      & "</p><p>Mot de passe<br><input type=""password"" size=""20"" " _
                                      & "id=""Password""></p><p><input type=" _
                                      & """hidden"" id=""OK"" name=""OK"" value=""0"">" _
                                      & "<input type=""submit"" value="" Reboot "" " _
                                      & "onclick=""VBScript:OK.Value=1""></p></div>"
        objIE.Document.Body.Style.overflow = "auto"
    	objIE.Document.body.style.backgroundcolor="lightblue"
        objIE.Visible = True
        objIE.Document.All.Password.Focus
        On Error Resume Next
        Do While objIE.Document.All.OK.Value = 0
            WScript.Sleep 200
            If Err Then    
                IELogin = Array( "", "" )
                objIE.Quit
                Set objIE = Nothing
                wscript.quit
            End if
        Loop
        On Error Goto 0
    	Login = objIE.Document.All.Login.Value
        Password = objIE.Document.All.Password.Value
        MsgBox "Nom Utilisateur est : " & Login,64,"Nom Utilisateur"
    	MsgBox "Le Mot de passe est : "& Password,64,"Mot de passe"
    	For i = 0 To UBound(ComputerName) 
    	command = "cmd /c wmic /node:"&ComputerName(i)&" /user:"&Login&" /password:"&Password&" os where primary=true call reboot"
    	msgbox command,64,"Command"
    	Execution = WS.Run(Command,0,True)
    	Next
        objIE.Quit
        Set objIE = Nothing

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 28
    Points : 26
    Points
    26
    Par défaut
    bonjour, merci de la réponse rapide, j'ai testé et ça ne marche pas.
    En fait je pense que le pb vient que dans la commande dos il faut que le login et le mot de passe soit entre "" ( ils sont utilisés dans la commande) est-ce qu'on peut le faire en vbs ?
    Par la même occasion, peut on éviter d'avoir le mot de passe qui s'affiche en clair ou les messages qui lance la commande ? la liste des postes changeant assez souvent une liste en fichier texte me serait plus pratique ( sans vouloir abusé ) Est-il possible d'avoir une log pour savoir ou on en était en cas de coupure du script ou micro ( cela n'est certes pas courant.. ) mais cela eviterait de rebooter 2 fois le même micro. En tout cas merci je l’étudie pour bien comprendre

  4. #4
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut
    Citation Envoyé par bolzardp Voir le message
    bonjour, merci de la réponse rapide, j'ai testé et ça ne marche pas.
    En fait je pense que le pb vient que dans la commande dos il faut que le login et le mot de passe soit entre "" ( ils sont utilisés dans la commande) est-ce qu'on peut le faire en vbs ?
    Par la même occasion, peut on éviter d'avoir le mot de passe qui s'affiche en clair ou les messages qui lance la commande ? la liste des postes changeant assez souvent une liste en fichier texte me serait plus pratique ( sans vouloir abusé ) Est-il possible d'avoir une log pour savoir ou on en était en cas de coupure du script ou micro ( cela n'est certes pas courant.. ) mais cela eviterait de rebooter 2 fois le même micro. En tout cas merci je l’étudie pour bien comprendre
    Pour ne pas afficher le Password il faut supprimer la ligne ou il y a MsgBox
    Pour "" les guillemets j'ai ajouté cette fonction:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function
    Bon pour le moment il faut tester la commande de reboot fonctionne ou pas ?
    voici le script modifié , mais avant d'exécuter ce dernier il faut modifier les noms des ordinateurs réduit en 3 juste pour le test puis on va voir du côté fichier à lire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
        Dim objIE,WS
    	'Liste des Ordinateurs à Rebooter
    	ComputerName = array("Ordinateur1","Ordinateur2","Ordinateur3")
    	Set WS = CreateObject("Wscript.Shell")
        Set objIE = CreateObject( "InternetExplorer.Application" )
        objIE.Navigate "about:blank"
        objIE.Document.Title = "Reboot à Distance " & String( 200, "*" )
        objIE.ToolBar        = False
        objIE.Resizable      = False
        objIE.StatusBar      = False
        objIE.Width          = 320
        objIE.Height         = 220
        With objIE.Document.ParentWindow.Screen
            objIE.Left = (.AvailWidth  - objIE.Width ) \ 2
            objIE.Top  = (.Availheight - objIE.Height) \ 2
        End With
        Do While objIE.Busy
            WScript.Sleep 200
        Loop
        objIE.Document.Body.InnerHTML = "<div align=""center""><p>Nom Utilisateur " _
    	                              & "<br><input type=""text"" size=""20"" " _
    								  & "id=""Login"" value=""Administrateur""></p>"_
                                      & "</p><p>Mot de passe<br><input type=""password"" size=""20"" " _
                                      & "id=""Password""></p><p><input type=" _
                                      & """hidden"" id=""OK"" name=""OK"" value=""0"">" _
                                      & "<input type=""submit"" value="" Reboot "" " _
                                      & "onclick=""VBScript:OK.Value=1""></p></div>"
        objIE.Document.Body.Style.overflow = "auto"
    	objIE.Document.body.style.backgroundcolor="lightblue"
        objIE.Visible = True
        objIE.Document.All.Password.Focus
        On Error Resume Next
        Do While objIE.Document.All.OK.Value = 0
            WScript.Sleep 200
            If Err Then    
                IELogin = Array( "", "" )
                objIE.Quit
                Set objIE = Nothing
                wscript.quit
            End if
        Loop
        On Error Goto 0
    	Login = objIE.Document.All.Login.Value
        Password = objIE.Document.All.Password.Value
        'MsgBox "Nom Utilisateur est : " & Login,64,"Nom Utilisateur"
    	'MsgBox "Le Mot de passe est : "& Password,64,"Mot de passe"
    	For i = 0 To UBound(ComputerName) 
    	command = "cmd /c wmic /node:"&ComputerName(i)&" /user:"&qq(Login)&" /password:"&qq(Password)&" os where primary=true call reboot"
    	msgbox command,64,"Command"
    	Execution = WS.Run(Command,0,True)
    	Next
        objIE.Quit
        Set objIE = Nothing
     
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 28
    Points : 26
    Points
    26
    Par défaut
    Ca marche bien sur 3 poste Vista par contre sur mon 4eme poste en Seven ca marche pas. Peut être la commande qui ne passe pas ? en tout cas c'est super merci. Je sais bien que je suis pénible, mais l'utilisation d'un fichier avec la liste des postes m'arrangerait quand même pas mal Et peut-on lancer la commande sans la valider à chaque fois par exemple avec une pause ou au retour de la commande que celle qui suit s’enchaine ?
    Merci encore pour la réactivité franchement c'est TOP Bravo

  6. #6
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut

    voila un fichier exemple nommé c:\Ordinateurs.txt
    Ordinateur1
    Ordinateur2
    Ordinateur3
    Ordinateur4
    Ordinateur5
    Ordinateur6
    Ordinateur7
    Ordinateur8
    Ordinateur9
    Ordinateur10
    et le script modifié devient comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Const ForReading = 1
    	Dim objIE,WS,Fso,f
    	Set WS = CreateObject("Wscript.Shell")
        Set objIE = CreateObject( "InternetExplorer.Application" )
        objIE.Navigate "about:blank"
        objIE.Document.Title = "Reboot à Distance " & String( 200, "*" )
        objIE.ToolBar        = False
        objIE.Resizable      = False
        objIE.StatusBar      = False
        objIE.Width          = 300
        objIE.Height         = 220
        With objIE.Document.ParentWindow.Screen
            objIE.Left = (.AvailWidth  - objIE.Width ) \ 2
            objIE.Top  = (.Availheight - objIE.Height) \ 2
        End With
        Do While objIE.Busy
            WScript.Sleep 200
        Loop
        objIE.Document.Body.InnerHTML = "<div align=""center""><p>Nom Utilisateur " _
    	                              & "<br><input type=""text"" size=""20"" " _
    								  & "id=""Login"" value=""Administrateur""></p>"_
                                      & "</p><p>Mot de passe<br><input type=""password"" size=""20"" " _
                                      & "id=""Password""></p><p><input type=" _
                                      & """hidden"" id=""OK"" name=""OK"" value=""0"">" _
                                      & "<input type=""submit"" value="" Reboot "" " _
                                      & "onclick=""VBScript:OK.Value=1""></p></div>"
        objIE.Document.Body.Style.overflow = "auto"
    	objIE.Document.body.style.backgroundcolor="lightblue"
        objIE.Visible = True
        objIE.Document.All.Password.Focus
        On Error Resume Next
        Do While objIE.Document.All.OK.Value = 0
            WScript.Sleep 200
            If Err Then    
                IELogin = Array( "", "" )
                objIE.Quit
                Set objIE = Nothing
                wscript.quit
            End if
        Loop
        On Error Goto 0
    	Login = objIE.Document.All.Login.Value
        Password = objIE.Document.All.Password.Value
        Set Fso = CreateObject("Scripting.FileSystemObject")
        Set f = Fso.OpenTextFile("c:\Ordinateurs.txt", ForReading)
        st=f.ReadAll
        ComputerName = split(st,vbcrlf)
        f.Close
    	For i = lbound(ComputerName) to ubound(ComputerName) 
    	command = "cmd /c wmic /node:"&ComputerName(i)&" /user:"&qq(Login)&" /password:"&qq(Password)&" os where primary=true call reboot"
    	Titre = "Reboot à Distance"
    	MsgBox "Reboot de l'ordinateur : " & ComputerName(i),64,Titre
    	Execution = WS.Run(Command,0,True)
    	Next
        objIE.Quit
        Set objIE = Nothing
     
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function

  7. #7
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut

    Voila un autre script avec vérification de l'existence du fichier c:\Ordinateurs.txt
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Titre = "Reboot à Distance © Developpez.com"
    Const ForReading = 1
    	Dim objIE,WS,Fso,f,Fichier
    	Fichier = "c:\Ordinateurs.txt"
    	Set WS = CreateObject("Wscript.Shell")
    	Set Fso = CreateObject("Scripting.FileSystemObject")
    	If Not Fso.FileExists(Fichier) Then
    	MsgBox "ATTENTION !!! "&vbcr& "Le fichier "&qq(Fichier)&" n'existe pas !!!",48,Titre
    	Wscript.Quit
    	Else
        Set f = Fso.OpenTextFile(Fichier,ForReading)
        st=f.ReadAll
        ComputerName = split(st,vbcrlf)
        f.Close
    	End If
        Set objIE = CreateObject( "InternetExplorer.Application" )
        objIE.Navigate "about:blank"
        objIE.Document.Title = "Reboot à Distance © Developpez.com" & String( 50, "*" )
        objIE.ToolBar        = False
        objIE.Resizable      = False
        objIE.StatusBar      = False
        objIE.Width          = 300
        objIE.Height         = 220
        With objIE.Document.ParentWindow.Screen
            objIE.Left = (.AvailWidth  - objIE.Width ) \ 2
            objIE.Top  = (.Availheight - objIE.Height) \ 2
        End With
        Do While objIE.Busy
            WScript.Sleep 200
        Loop
        objIE.Document.Body.InnerHTML = "<div align=""center""><p><h3 style='color:Red'>Nom Utilisateur " _
    	                              & "<br><input type=""text"" style='color:Blue' size=""20"" " _
    								  & "id=""Login"" value=""Administrateur""></h3></p>"_
                                      & "</p><p><h3 style='color:Red'>Mot de passe<br><input type=""password"" style='color:Blue' size=""20"" " _
                                      & "id=""Password""></h3></p><p><input type=" _
                                      & """hidden"" id=""OK"" name=""OK"" value=""0"">" _
                                      & "<input type=""submit"" value="" Reboot "" " _
                                      & "onclick=""VBScript:OK.Value=1""></p></div>"
        objIE.Document.Body.Style.overflow = "auto"
    	objIE.Document.body.style.backgroundcolor="lightblue"
        objIE.Visible = True
        objIE.Document.All.Password.Focus
        On Error Resume Next
        Do While objIE.Document.All.OK.Value = 0
            WScript.Sleep 200
            If Err Then    
                IELogin = Array( "", "" )
                objIE.Quit
                Set objIE = Nothing
                wscript.quit
            End if
        Loop
        On Error Goto 0
    	Login = objIE.Document.All.Login.Value
        Password = objIE.Document.All.Password.Value
    	For i = lbound(ComputerName) to ubound(ComputerName) 
    	command = "cmd /c wmic /node:"&ComputerName(i)&" /user:"&qq(Login)&" /password:"&qq(Password)&" os where primary=true call reboot"
    	MsgBox "Reboot de l'ordinateur : " & ComputerName(i),64,Titre
    	Execution = WS.Run(Command,0,True)
    	Next
        objIE.Quit
        Set objIE = Nothing
     
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function

  8. #8
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 28
    Points : 26
    Points
    26
    Par défaut
    Merci je suis plus au travail, je testerais ça des lundi encore merci

  9. #9
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 28
    Points : 26
    Points
    26
    Par défaut
    Bonjour,

    J'ai testé ce matin tout marche bien. J'ai retiré la ligne
    'MsgBox "Le Mot de passe est : "& Password,64,"Mot de passe" pour eviter d'avoir à valider chaque reboot de poste, mais le probleme c'est que sur une longue liste de poste on ne sait plus ou on en est.
    Ma question : A la place de cette ligne message box ne pourrait-on pas ouvrir par exemple le boc notes ou un fichier log et y mettre dedans le poste qui reboot ce qui permettrait d'avoir un bon suivit.
    Merci de votre réponse.

  10. #10
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut
    Citation Envoyé par bolzardp Voir le message
    Bonjour,
    J'ai testé ce matin tout marche bien. J'ai retiré la ligne
    'MsgBox "Le Mot de passe est : "& Password,64,"Mot de passe" pour eviter d'avoir à valider chaque reboot de poste, mais le probleme c'est que sur une longue liste de poste on ne sait plus ou on en est.
    Ma question : A la place de cette ligne message box ne pourrait-on pas ouvrir par exemple le boc notes ou un fichier log et y mettre dedans le poste qui reboot ce qui permettrait d'avoir un bon suivit.
    Merci de votre réponse.
    il faut voir maintenant la Comment écrire dans un fichier texte ?

  11. #11
    Membre averti
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2011
    Messages
    163
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2011
    Messages : 163
    Points : 304
    Points
    304
    Par défaut
    Salut bolzardp !

    Je me suis déjà penché sur cette question, je te transmets mes outils ...
    2 fichiers sont nécessaires :
    REDEMARRAGE_DES_POSTES.vbs
    LISTE_PC.txt

    Le code est le suivant :
    REDEMARRAGE_DES_POSTES.vbs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    LISTE_PC.txt
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    NOMPC1
    NOMPC1
    NOMPC3
    (etc...)

    Voilà, j'espère que ça t'aidera !

    Ps : La version sans interface pour une tâche planifiée par exemple
    REDEMARRAGE_DES_POSTES_SILENT.vbs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    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")
    Public StrComputer, onlinestate
    date_heure = now
     
    Rep_Courant = WScript.ScriptFullName
    Rep_Courant = left(Rep_Courant,InStrRev(Rep_Courant,"\"))
     
    ' ******************************
    ' Variables à modifier si besoin
    ' ******************************
     
    Liste_Pc = "LISTE_PC.txt"
    Fichier_tmp = "LISTE_TMP.txt"
    Fichier_Rapport = "RAPPORT_RESTART.txt"
     
    on error resume next
     
    ' ******************************
    ' 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

  12. #12
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 28
    Points : 26
    Points
    26
    Par défaut
    Merci à tous de vos réponses, je vais tester tout ca, c'est vrai que j'ai un peu de mal pour faire ecrire les postes dans un fichier suite à l'execution de la commande je suis vraiment un noob et j'apprécie bien votre aide.
    merci

  13. #13
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 28
    Points : 26
    Points
    26
    Par défaut
    Bonjour Cachlab,

    J'ai essayé le script et j'ai une erreur ligne 40 caractere 169, je travail sur une active directory avec une session compte standard d'ou dans la ligne de commande le compte administrateur utilisé, dois-je changer des parametres ?
    Lesquels ?
    j'essaie de décrypter le script qui a l'air tres bien sans vouloir vexé hackoofr qui a fait du bon travail sur mes questions ( le script fonctionne bien, il me manque juste le controle de l'historique) La fonction ping à l'air bien aussi ouf !! dur dur pour moi mais je m'accroche .
    cdlt

  14. #14
    Membre averti
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2011
    Messages
    163
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2011
    Messages : 163
    Points : 304
    Points
    304
    Par défaut
    Re ! Oui bizarre, j'ai du faire une fausse manip, la ligne 41 n'a pas de raison d'être ...
    Voici la version corrigée :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    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
    ' **************************
     
    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
    ' **************************************
     
    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
    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
    Sinon, oui, cette partie sert à vérifier que le script est lancé avec un compte disposant des droits d'admin sur les postes distants. Tu peux tout supprimer de la ligne 35 à 43 sans souci.
    Ou simplement définir le compte que tu souhaites utiliser en ligne 13 : Admin = "NomdetoncompteAdmin"

    Pour Hackhoof, je ne pense pas qu'il se vexera car c'est en grande partie grâce à lui (et aux autres résidents du forum bien sûr ) que j'ai fais de gros progrès ces derniers mois !
    Je pense qu'il est plutôt du style à être fier de ses "élèves" !

  15. #15
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut
    Citation Envoyé par bolzardp Voir le message
    Bonjour Cachlab,
    j'essaie de décrypter le script qui a l'air tres bien sans vouloir vexé hackoofr qui a fait du bon travail sur mes questions ( le script fonctionne bien, il me manque juste le controle de l'historique) La fonction ping à l'air bien aussi ouf !! dur dur pour moi mais je m'accroche .
    cdlt

    Au contraire je suis content pour la contribution de Cachlab car ça donne d'autres idées complémentaires pour enrichir cette discussion et pour atteindre la finalité ce script
    Donc Cachlab vous avez un +1 de ma part

  16. #16
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 28
    Points : 26
    Points
    26
    Par défaut
    Cachlab,

    Après plusieurs test je n'arrive pas à rebooter un poste, alors qu'avec la commande DOS mise à la sauce VBS de hackoofr cela fonctionne bien ( même quand la session est fermée sur le poste - mire ctrl+alt+suppr ) Dans la ligne de commande DOS je spécifie mon compte Administrateur de domaine et son mot de passe ce qui me permet de rebooter des postes qui sont sur d'autres site que le mien tout en restant sur ma session utilisateur standard.
    L'integration du compte Admin est sous la forme: DomaineAD\compte Admin exemple: Domaine = KXXSS et compte Admin = AdmKXXSS25 donc on aura pour le login: KXXSS\AdmKXXSS25. Pour le moment je peux rebooter des postes Win2000, WinXP, Vista pour Seven il faut que je test sur plusieurs postes je sais pas si le pb vient de mon poste de test.
    En tout cas le fichier de rapport me convient bien.
    Merci

  17. #17
    Membre averti
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2011
    Messages
    163
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2011
    Messages : 163
    Points : 304
    Points
    304
    Par défaut
    Bolzardp !

    En effet, il te faudrait une compil de nos 2 scripts ...
    Le mien nécessite d'être utilisé depuis une session admin, ce qui requière de te délogger et de te relogger en "KXXSS/AdmKXXSS25".

    En ce qui me concerne, j'ai plusieurs machines sous la main et plusieurs sessions ouvertes simultanément ... je ne m'étais donc pas posé cette question à l'époque, lors de l'écriture du script (d'ailleur en le relisant, je constate qu'il mériterait quelques optimisations).

    J'aime beaucoup la fenêtre de saisie de compte de HackHoof, ainsi que son mode de lecture du fichier txt bien plus efficace.
    Cependant, il faudrait ajouter une gestion de la validité du compte saisi ainsi qu'une étape de vérification de l'existence du poste sur le réseau.
    Et bien sûr le fichier log final ...

    Un peu tard pour m'y mettre ce soir ... On en reparle demain.
    A moins que Hackhoof soit motivé !

  18. #18
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut
    Citation Envoyé par Cachlab Voir le message
    A moins que Hackoofr soit motivé !
    Comment vouliez-vous que je me sois motivé lorsque je me la tête et je ne reçois aucun

  19. #19
    Membre averti
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2011
    Messages
    163
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2011
    Messages : 163
    Points : 304
    Points
    304
    Par défaut

    Pardon c'est vrai que tu mérites amplement un wagon de !
    Honte sur moi de ne te l'avoir pas retourné d'ailleur ...
    Oublie corrigé !

    bolzardp je regarde le script dans la journée ...

  20. #20
    Membre averti
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2011
    Messages
    163
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2011
    Messages : 163
    Points : 304
    Points
    304
    Par défaut
    Salut ! Bon j'ai bossé un peu mais interrompu cause crash du cluster de données ...

    Toujours 2 fichiers requis LISTE_PC.txt et REDEMARRAGE_PC.vbs
    Voici le début du code (incomplet).

    LISTE_PC.txt
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    ' Remarques et Commentaires
     
    ' Postes de la Compta
    ORDINATEUR1
    ORDINATEUR2
    ORDINATEUR3
     
    ' Postes de la RH
    ORDINATEUR4
    ORDINATEUR5
    REDEMARRAGE_PC.vbs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    '*** Définition des variables globale ***
     
    	Titre = "Redémarrage de postes à distance @ Developpez.com"
    	Const ForReading = 1, ForWriting = 8
    	Public StrComputer, onlinestate, Fichier_log, WSHShell, Fichier_tmp, msg()
    	Dim oFSO, oFl, ecr, lect, ComputerName
    	Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
    	Set WSHShell = WScript.CreateObject("WScript.Shell")
    	Set WSHNetwork = CreateObject("WScript.Network")
     
    ' *** Définition des variables d'environnement ***
     
    	Liste_pc = "LISTE_PC.txt"
    	Fichier_tmp = "LISTE_TMP.txt"
    	Fichier_log = "RAPPORT_RESTART.txt"
     
    ' *** Définition des variables locales ***
     
    	Redim msg(5)
    	msg(0) = "__________________________________________"
    	msg(1) = "Liste des postes introuvable " & dblquote(Liste_pc)
    	msg(2) = "Aucun poste dans la liste " & dblquote(Liste_pc)
    	msg(3) = "Début du script : "
    	msg(4) = "Script interrompu : "
    	msg(5) = "Fin du script : "
     
     
    ' *** Début du Script ***
     
    	' Test Fichier_Log existe
    	If Not oFSO.FileExists(Fichier_log) Then oFSO.CreateTextFile(Fichier_log)
    	Date_Heure = now
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(3) & Date_Heure & VbCrLf & VbCrLf : ecr.Close
     
    	' Test Liste_Pc existe
    	If Not oFSO.FileExists(Liste_Pc) Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(1) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
    	End If
     
    	' Test Liste_Pc non vide
    	Set oFl = oFSO.GetFile(Liste_Pc)
    	If oFl.Size = 0 Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(2) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
    	End If
     
    	' Création Fichier_tmp
    	if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
    	oFSO.CreateTextFile(Fichier_tmp)
     
    	' Correction de Liste_Pc en Fichier_tmp
     
    	date_heure = now
    	Set lect = oFSO.OpenTextFile(Liste_Pc, ForReading)
    	Set ecr = oFSO.OpenTextFile(Fichier_tmp, ForWriting)
    		While Not lect.AtEndOfStream
    		Texte = lect.ReadLine
    		Texte = Trim(Texte)
    		prem_car = lcase(left(Texte,1))
    			if ( Len(Texte) > 0 ) and InStr("'", prem_car) = 0 Then
    			ecr.Writeline Texte
    			End if	
    		Wend
    	lect.Close
    	ecr.Close
     
    	' Test Fichier_tmp non vide
     
    	Set oFl = oFSO.GetFile(Fichier_tmp)
    	If oFl.Size = 0 Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write msg(2) & VbCrLf : ecr.Close : Call fin_Prog : WScript.Quit
    	End If
     
    	' Lecture du Fichier_tmp
     
    	Set lect = oFSO.OpenTextFile(Fichier_tmp, ForReading)
    	st = lect.ReadAll
    	ComputerName = Split(st, vbCrLf)
    	lect.Close
     
     
    ' !!! EN TRAVAUX !!!
    ' !!! EN TRAVAUX !!!
    ' !!! EN TRAVAUX !!!
    ' !!! EN TRAVAUX !!!
    ' !!! EN TRAVAUX !!!
    ' !!! EN TRAVAUX !!!
     
     
     
    ' *** Fin du script
     
    Date_Heure = now
    Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) :  ecr.Write VbNewLine & msg(5) & Date_Heure & VbCrLf & msg(0) & VbCrLf : ecr.Close
    if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
    WSHShell.Run ("C:\WINDOWS\system32\notepad.exe " & Fichier_log)
    WScript.Quit
     
    ' *** Sous-Fonction Fin programme
     
    Sub fin_prog
    Date_Heure = now
    Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) :  ecr.Write VbNewLine & msg(4) & Date_Heure & VbCrLf & msg(0) & VbCrLf : ecr.Close
    if oFSO.FileExists(Fichier_tmp) Then oFSO.DeleteFile Fichier_tmp, True
    WSHShell.Run ("C:\WINDOWS\system32\notepad.exe " & Fichier_log)
    End Sub
     
    ' *** Fonction Guillemets
     
    Function dblquote(strIn)
    dblquote = Chr(34) & strIn & Chr(34)
    End Function

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Outil pour faire des "GUI" pour programme dos
    Par Seymonn dans le forum Pascal
    Réponses: 1
    Dernier message: 02/12/2013, 19h45
  2. PB compilation sur Package pour programme dos.
    Par Fbartolo dans le forum C++Builder
    Réponses: 5
    Dernier message: 15/06/2006, 19h29
  3. [VBS] Fonction vbscript pour transformer en binaire
    Par roots_man dans le forum VBScript
    Réponses: 2
    Dernier message: 30/08/2005, 08h48
  4. Réponses: 7
    Dernier message: 16/04/2005, 08h55
  5. Réponses: 4
    Dernier message: 04/07/2003, 19h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo