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. #21
    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 !

    Voici le script terminé ... à mon niveau en tous cas !

    Je ne suis pas compétent pour ce qui concerne la gestion des erreurs dans la fenêtre de saisie du mot de passe (compte inexistant, erreur de mot de passe, droits du compte insuffisants).

    Du coup on n'est pas sûr que la demande de redémarrage ait été acceptée par le poste distant ...
    J'espère que Hackhoof voudra bien jeter un coup d'oeil pour finaliser cela !

    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
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    '*** 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(7)
    	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 : "
    	msg(6) = " : Poste inaccessible"
    	msg(7) = " : Redémarrage demandé"
     
     
    ' *** 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
     
    	' Saisie compte Admin
     
    	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) -1
    	strComputer = ComputerName(i)
    	Call Online
    	If onlinestate = 0 Then
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write ComputerName(i) & msg(6) & VbCrLf : ecr.Close
    	Else
    	command = "cmd /c wmic /node:"&ComputerName(i)&" /user:"&dblquote(Login)&" /password:"&dblquote(Password)&" os where primary=true call reboot"
    	Execution = WSHShell.Run(Command,0,True)
    	Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write ComputerName(i) & msg(7) & VbCrLf : ecr.Close
    	End if
    	Next
    	objIE.Quit
    	Set objIE = Nothing
     
    ' *** 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
     
    ' *** Sous-Fonction Ping
     
    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 onlinestate = 1 else onlinestate = 0
    Next
    End Sub
     
     
    ' *** Fonction Guillemets
     
    Function dblquote(strIn)
    dblquote = Chr(34) & strIn & Chr(34)
    End Function

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut
    Citation Envoyé par Cachlab Voir le message
    Salut !

    Voici le script terminé ... à mon niveau en tous cas !

    Je ne suis pas compétent pour ce qui concerne la gestion des erreurs dans la fenêtre de saisie du mot de passe (compte inexistant, erreur de mot de passe, droits du compte insuffisants).

    Du coup on n'est pas sûr que la demande de redémarrage ait été acceptée par le poste distant ...
    J'espère que Hackhoof voudra bien jeter un coup d'oeil pour finaliser cela !

    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
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    '*** 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(7)
        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 : "
        msg(6) = " : Poste inaccessible"
        msg(7) = " : Redémarrage demandé"
     
     
    ' *** 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
     
        ' Saisie compte Admin
     
        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) -1
        strComputer = ComputerName(i)
        Call Online
        If onlinestate = 0 Then
        Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write ComputerName(i) & msg(6) & VbCrLf : ecr.Close
        Else
        command = "cmd /c wmic /node:"&ComputerName(i)&" /user:"&dblquote(Login)&" /password:"&dblquote(Password)&" os where primary=true call reboot"
        Execution = WSHShell.Run(Command,0,True)
        Set ecr = oFSO.OpenTextFile(Fichier_log, ForWriting) : ecr.Write ComputerName(i) & msg(7) & VbCrLf : ecr.Close
        End if
        Next
        objIE.Quit
        Set objIE = Nothing
     
    ' *** 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
     
    ' *** Sous-Fonction Ping
     
    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 onlinestate = 1 else onlinestate = 0
    Next
    End Sub
     
     
    ' *** Fonction Guillemets
     
    Function dblquote(strIn)
    dblquote = Chr(34) & strIn & Chr(34)
    End Function

    +1 CashLab "Very Nice Script"
    Beau travail pour votre persévérance à moins que bolzardp n'est pas encore satisfait, peut-être il veut d'autres améliorations

  3. #23
    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 de votre avancé, je rentre à l'instant d'une formation de 2 jours, je regarderai plus en détail ces scripts demain.
    Merci

  4. #24
    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

    Je ne suis pas au travail aujourd’hui, j'ai fait quelques tests chez moi et je trouve le script parfait. Je le testerais au boulot demain et je vous dirais ce qu'il en est.
    En tout cas un grand à vous deux Vous êtes très fort


    Ps: Je fais aussi des tests de débits réseaux en utilisant des transfert FTP ( toujours sous DOS je sais je suis un .
    Mais avant de vous solliciter je vais rechercher dans la

  5. #25
    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 à tous,

    C'est bon j'ai fait mes tests et tout fonctionne bien.
    Encore pour votre participation.
    Pour moi c'est

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

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