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

Scripts/Batch Discussion :

Batch en VBS pour planificateur spécial


Sujet :

Scripts/Batch

  1. #1
    apt
    apt est déconnecté
    Membre régulier
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Points : 118
    Points
    118
    Par défaut Batch en VBS pour planificateur spécial
    Bonjour à tous

    Est-il possible d’avoir un fichier batch en VBs, pour planifier manuellement un arrêt ou un redémarrage de Windows après un certain temps, en cas d’inactivité ou en cas d’un blocage d’une application qui est en cours d’exécution (ex : Ne répond pas) ou en cas ou l’application vous demande si tu veux redémarrer le PC (Comment capter cela ??)

    Effectivement il faut prévenir l’annulation de cette planification en cas ou on aura changé d’avis.

    J'ai posté ICI par erreur

    Merci d’avance.

  2. #2
    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

    Peut-être quelque chose comme ceci : Batch reboot with message delay

    Code BAT : 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
    @echo off
    shutdown -r -t 600 -c "Your machine you need to reboot in 5 minutes." -f  
    Call :AskQuestion
    exit
    ::***********************************************************************
    :AskQuestion
    (
        echo    Set Ws = CreateObject("wscript.shell"^)
        echo    wscript.sleep 180000
        echo    Answ = MsgBox("Did you want to cancel the scheduled reboot of your the computer ?"_
        echo ,VbYesNo+VbQuestion,"Did you want to cancel the scheduled reboot of your the computer ?"^)
        echo    If Answ = VbYes then 
        echo        Return = Ws.Run("cmd /c Shutdown -a",0,True^)
        echo    Else
        echo        wscript.Quit(1^)
        echo    End If
    )>"%tmp%\%~n0.vbs"
    Start "" "%tmp%\%~n0.vbs"

  3. #3
    apt
    apt est déconnecté
    Membre régulier
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Points : 118
    Points
    118
    Par défaut
    Bonjour hackoofr,

    Merci pour le code, mais j’aimerais le voir avec un menu s’il est possible :

    1. Arrêt
    2. Redémarrage
    3. En cas de blocage de l’application en cours (capter quelle application est en cours d’exécution)
    4. Inactivité
    5. Annuler planification



    Pour la planification des quatre premières options, je devrais définir manuellement le temps d'avant l'exécution.
    Merci

  4. #4
    apt
    apt est déconnecté
    Membre régulier
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Points : 118
    Points
    118
    Par défaut
    Bonjour,

    Voici un batch qui répond bien en général à ma demande, mais reste à évoluer pour le reste des options du menu :

    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
    @Echo off
    GOTO Menu
    
    :Menu
    Echo ----------------------------------------
    Echo ! Gestion de l'arret du systeme !
    Echo ----------------------------------------
    Echo 1 - Planifier un arret du systeme.
    Echo 2 - Planifier un redemarrage du systeme.
    Echo 3 - Annuler l'arret planifier.
    Echo ----------------------------------------
    SET /p Action=Votre Choix :
    
    IF %Action% == 1 GOTO PlanifierArret
    IF %Action% == 2 GOTO PlanifierRedemarrage
    IF %Action% == 3 GOTO AnnulerPlanification
    IF %Action% GTR 3 GOTO SaisieIncorrecte
    
    :AnnulerPlanification
    shutdown -a
    Echo Planification Annulee
    Goto FinProgramme
    
    :PlanifierRedemarrage
    Echo Info : 1 heure = 3600 secondes
    SET /p Secondes= Secondes avant le redemarrage du systeme :
    IF '%Secondes%' == '' GOTO PlanifierRedemarrage
    shutdown -r -t %Secondes%
    GOTO FinProgramme
    
    :PlanifierArret
    Echo Info : 1 heure = 3600 secondes
    SET /p Secondes= Secondes avant l'arret du systeme :
    IF '%Secondes%' == '' GOTO PlanifierArret
    shutdown -s -f -t %Secondes%
    GOTO FinProgramme
    
    :SaisieIncorrecte
    CLS
    Echo ! ! ! ! ! ! Valeur saisie incorrecte ! ! ! ! ! !
    GOTO Menu
    
    :FinProgramme
    Merci.

  5. #5
    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

    Voici quelque chose inspiré par ce code avec un menu dynamique avec création d'un raccourci avec icône dans le bureau :
    Code BAT : 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
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    @echo off
    setlocal enabledelayedexpansion
    Set "Delay2Shutdown=600"
    Set "Delay2Reboot=600"
    Set TmpFile=%Temp%\TmpFile.txt
    Set Resultat=%Temp%\KillResult.txt
    Set "MyKey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
    If Exist %TmpFile% Del %TmpFile%
    If Exist %Resultat% Del %Resultat%
    Set "MyFile=%~f0"
    Set "ShorcutName=Shtutdown_Reboot"
    (
    echo Call Shortcut("%MyFile%","%ShorcutName%"^)
    echo ^'**********************************************************************************************^)
    echo Sub Shortcut(CheminApplication,Nom^)
    echo    Dim objShell,DesktopPath,objShortCut,MyTab
    echo    Set objShell = CreateObject("WScript.Shell"^)
    echo    MyTab = Split(CheminApplication,"\"^)
    echo    If Nom = "" Then
    echo    Nom = MyTab(UBound(MyTab^)^)
    echo    End if
    echo    DesktopPath = objShell.SpecialFolders("Desktop"^)
    echo    Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Nom ^& ".lnk"^)
    echo    objShortCut.TargetPath = Dblquote(CheminApplication^)
    echo    ObjShortCut.IconLocation = "Shell32.dll,44"
    echo    objShortCut.Save
    echo End Sub
    echo ^'**********************************************************************************************
    echo ^'Fonction pour ajouter les doubles quotes dans une variable
    echo Function DblQuote(Str^)
    echo    DblQuote = Chr(34^) ^& Str ^& Chr(34^)
    echo End Function
    echo ^'**********************************************************************************************
    ) > %temp%\Shortcutme.vbs
    Start /Wait %temp%\Shortcutme.vbs
    Del %temp%\Shortcutme.vbs
    ::****************************************************************************************************
    Title Dynamic Menu (Shutdown/Reboot) (Start/Kill Process) by Hackoo 2016
    :menuLOOP
    Color 1E & Mode con cols=78 lines=20
    echo(
    echo(       =============================Menu==============================
    echo(
    for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo         %%A  %%B
    echo(
    echo(       ===============================================================
    set choice=
    echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
    echo( & call :menu_[%choice%]
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[1] (ARRET)/(SHUTDOWN)
    cls & color 0A
    Call:SkipLine 5
    Call:Tab 3
    echo %x% Please Wait for a while .... 
    TimeOut /T 1 /NoBreak>nul
    shutdown -s -t %Delay2Shutdown% -c "Your machine will shutdown in 5 minutes." -f 
    GOTO:menuLOOP
    ::********************************************************************************************4
    :menu_[2] (REDEMARRAGE)/(REBOOT)
    cls & color 0A
    Call:SkipLine 5
    Call:Tab 3
    echo %x% Please Wait for a while .....
    TimeOut /T 1 /NoBreak>nul
    shutdown -r -t %Delay2Reboot% -c "Your machine will reboot in 5 minutes." -f 
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[3] (APPLICATION PAS DE REPONSE)/(APPLICATION NOT RESPONDING)
    cls & color 0A
    Call:SkipLine 10
    Call:Tab 3
    echo %x% Please Wait for a while .. Launching  ...
    TimeOut /T 1 /NoBreak>nul
    Start "Killing not responding application" cmd /k taskkill.exe /f /fi "status eq not responding" >> %Resultat%
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[4] (ANNULER ARRET/REDEMARRAGE)/(CANCEL SHUTDOWN/REBOOT)
    cls & color 0A
    Call:SkipLine 5
    Call:Tab 7
    echo %x% Please Wait for a while ....
    TimeOut /T 1 /NoBreak>nul
    (
        echo    Set Ws = CreateObject("wscript.shell"^)
        echo    Answ = MsgBox("Did you want to cancel the scheduled reboot of your the computer ?"_
        echo ,VbYesNo+VbQuestion,"Did you want to cancel the scheduled reboot of your the computer ?"^)
        echo    If Answ = VbYes then 
        echo        Return = Ws.Run("cmd /c Shutdown -a",0,True^)
        echo    Else
        echo        wscript.Quit(1^)
        echo    End If
    )>"%tmp%\%~n0.vbs"
    Start "" "%tmp%\%~n0.vbs"
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[5] (START PROCESS/MULTI-PROCESS)/(LANCER PROSESSUS)
    cls & color 0A
    echo(
    echo      Enter the process name or processes names separated by a space
    echo(
    Set /p "MyProcess=What process(es) do you want to Start ?>"
    cls  
    Call:SkipLine 8
    Call:Tab 6
    echo %x% The process(es) "%MyProcess%" is launched ...
    TimeOut /T 1 /NoBreak>nul
    For %%a in (%Myprocess%) Do (Start %%a)
    GOTO :menuLOOP
    ::********************************************************************************************
    :menu_[6] (KILL PROCESS/MULTI-PROCESS)/(TUER PROCESSUS)
    Title Process Killer by Hackoo 2016
    cls & color 0B
    echo(
    echo     Enter the process name or processes names separated by a space
    echo(
    set /p "process=What process(es) do you want to kill ?>"
    cls & color 0C
    Title Killing "%process%" ...
    Call:SkipLine 8
    Call:Tab 7
    echo %x% Killing "%process%" ...
    echo(
    echo %date% *** %time% >> %TmpFile%
    For %%a in (%process%) Do Call :KillMyProcess %%a
    Cmd /U /C Type %TmpFile% > %Resultat%
    Start %Resultat%
    GOTO :menuLOOP
    ::******************************************************************************************
    :menu_[7] (Disable execution for one application choosen by the user)
    Mode con cols=90 lines=15 & Cls & color 0C
    echo(
    echo Enter Application name with its extension to block and disable it like "Chrome.exe"
    echo(
    Set /p "App=Enter Application name to block and diable it > "
    IF [%App%] == [] GOTO:menuLOOP
    REG ADD "%MyKey%\%App%" /f
    REG ADD "%MyKey%\%App%" /v Debugger /t REG_SZ /d Block /f
    Start "" "%App%"
    GOTO:menuLOOP
    ::*****************************************************************************************
    :menu_[8] (Enable execution for one application choosen by the user)
    Mode con cols=90 lines=15 & Cls & color 0A
    echo(
    echo Enter Application name with its extension to unblock and enable it like "Chrome.exe"
    echo(
    Set /p "App=Enter Application name to unblock and enable it> "
    IF [%App%] == [] GOTO:menuLOOP
    REG ADD "%MyKey%\%App%" /f
    REG ADD "%MyKey%\%App%" /v Debugger /t REG_SZ /d "" /f
    Start "" "%App%"
    GOTO:menuLOOP
    ::*****************************************************************************************
    :menu_[9] (Disable and block the execution of all Browsers)
    Mode con cols=90 lines=15 & Cls & color 0C
    Set Browsers=iexplore.exe firefox.exe chrome.exe opera.exe
    For %%a in (%Browsers%) Do Call :BlockExecution %%a
    GOTO:menuLOOP
    ::*****************************************************************************************
    :menu_[10] Enable and unblock the execution of all Browsers)
    Mode con cols=90 lines=15 & Cls & color 0A
    Set Browsers=iexplore.exe firefox.exe chrome.exe opera.exe
    For %%a in (%Browsers%) Do Call :UnBlockExecution %%a
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[11] Take screenshots of your applications (Windows 7,8,10)
    Start "" snippingtool.exe
    GOTO :menuLOOP
    ::*****************************************************************************************
    :BlockExecution
    REG ADD "%MyKey%\%~nx1" /f
    REG ADD "%MyKey%\%~nx1" /v Debugger /t REG_SZ /d Block /f
    Exit /b
    ::*****************************************************************************************
    :UnBlockExecution
    REG ADD "%MyKey%\%~nx1" /f
    REG ADD "%MyKey%\%~nx1" /v Debugger /t REG_SZ /d "" /f
    Exit /b
    ::*****************************************************************************************
    :Tab
    set "x="
    For /L %%I In (1,1,%1) Do Set "x=!x!    "
    REM                                  ^-- this is a TAB
    goto :eof
    ::*********************************************************************************************
    :SkipLine
    For /L %%I In (1,1,%1) Do Echo(
    Goto:Eof
    ::*********************************************************************************************
    :KillMyProcess
    Taskkill /IM "%~n1.exe" /F >> %TmpFile% 2>&1
    echo ***************************************************************************** >> %TmpFile%
    exit /b
    ::*****************************************************************************************

  6. #6
    apt
    apt est déconnecté
    Membre régulier
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Points : 118
    Points
    118
    Par défaut
    Salut hackoofr,

    Voici ce que j'obtiens lorsque je lance le script :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    =============================Menu==============================
    ===============================================================
    Make a choice or hit ENTER to quit:

  7. #7
    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 apt Voir le message
    Salut hackoofr,

    Voici ce que j'obtient lorsque je lance le script :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    =============================Menu==============================
    ===============================================================
    Make a choice or hit ENTER to quit:
    Chez moi sur Windows 7 (32 bits) j'ai comme ceci :


  8. #8
    apt
    apt est déconnecté
    Membre régulier
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Points : 118
    Points
    118
    Par défaut
    J'ai refais un copier coller du code et ça donne le menu en photo.

    Merci hackoofr.

    Je vais essayé de comprendre le code e premier, parce que c'est tout nouveau pour moi

    Et si ça demande une modification pour mon besoin, je vais la citer

  9. #9
    apt
    apt est déconnecté
    Membre régulier
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Points : 118
    Points
    118
    Par défaut
    Je ne peux t'envoyer un mp hackoofr, alors tu peux vider ta boite de réception (elle est pleine) ?

  10. #10
    apt
    apt est déconnecté
    Membre régulier
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Points : 118
    Points
    118
    Par défaut
    Bonjour,

    Pour détecter une application qui "a cessé de fonctionner" (pas de réponse), on teste ceci :

    status eq not responding

    Peut-on par la même manière tester si une application est en veuille ?

    status eq hibernate

  11. #11
    apt
    apt est déconnecté
    Membre régulier
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Points : 118
    Points
    118
    Par défaut
    Chercher coté "Status" ce n'est pas possible puisqu'il y a trois valeurs possibles [Running, Not responding et Unknown].

    Alors, j'ai pensé avoir une comparaison coté MEMUSAGE pour voir la consommation mémoire lors du lancement, en cours de travail et à la fin de travail.

    La consommation au début est moins que pendant le travail de l'application, ensuite à la fin la mémoire allouée sera revue à la baisse.

    Je crois que c'est comme ça qu'on peut détecter une application en "veuille"

  12. #12
    apt
    apt est déconnecté
    Membre régulier
    Inscrit en
    Mai 2002
    Messages
    867
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 867
    Points : 118
    Points
    118
    Par défaut
    Un petit exemple (qui ne marche pas encore !?)

    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
    @echo off
    set mem1=0
    set mem2=0
    
    rem démarrer l'application
    start "ZHPDiag 2016" /wait /b "C:\Users\Apt\Desktop\ZHPDiag3.exe
    
    rem mémoriser la mémoire allouée au programme lors du lancement
    for /f "tokens=5" %g in ('tasklist /fi "imagename eq zhpdiag3.exe" ^| findstr " K"') do (
       set mem1=%g
    )
    
    rem attendre 60 secondes
    sleep 60
    
    rem étiquette ou on peut lire la mémoire actuelle allouée au programme en cours d'exécution
    :Memoire
    for /f "tokens=5" %g in ('tasklist /fi "imagename eq zhpdiag3.exe" ^| findstr " K"') do (
       set %mem2%=%g
    )
    
    rem si mem2 est inférieure que mem1 alors l'application a fini son travail
    if %mem2% lss %mem1% (
    echo l'application ZHPDIag a fini son scan
    start "Calculatrice" /wait /b "c:\windows\system32\calc.exe"
    ) else ( 
    echo pas encore fini le scan
    goto Memoire
    )
    goto end
    pause
    Quelqu'un peu corriger ce code ?

    Merci.

Discussions similaires

  1. Batch en VBS pour planificateur spécial
    Par apt dans le forum Scripts/Batch
    Réponses: 0
    Dernier message: 10/11/2016, 20h15
  2. Réponses: 6
    Dernier message: 29/08/2007, 09h19
  3. (Batch et VBS) Petit probléme avec un script batch VBS
    Par Edoxituz dans le forum Windows
    Réponses: 11
    Dernier message: 27/02/2006, 17h21
  4. Script VBS pour connaitre taille d'une image
    Par fredoh dans le forum Windows
    Réponses: 2
    Dernier message: 24/02/2006, 14h27
  5. [Batch] Tit prog pour ouvrir une page internet
    Par toniovitch dans le forum Windows
    Réponses: 1
    Dernier message: 17/09/2005, 16h20

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