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 :

Lancer, Quitter un programme, une optimisation de ce code ?


Sujet :

Scripts/Batch

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2015
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2015
    Messages : 18
    Points : 23
    Points
    23
    Par défaut Lancer, Quitter un programme, une optimisation de ce code ?
    Bonsoir.

    Je débute tout juste mon apprentissage sur les scripts Batch et j'aimerais avoir quelques conseils afin d'optimiser un script qui lance/quitte un programme (exemple Skype) via un menu, et qui affiche si celui ci fonctionne ou pas.

    Je me suis aidé de pas mal de guides et exemples sur le net et je vous prie de m'excuser pour les petites maladresses que je pourrais fournir dans le script à suivre.

    Voici mes questions:
    1. Est-ce que ce script peut être optimiser ? Utilisation de variables ? Meilleure syntaxe ou présence de script inutile ?
    En effet, je souhaite continuer avec divers processus/programmes à fermer avant de pouvoir lancer des jeux vidéos (j'aimerais faire l'équivalent d'un GameBooster dont le plus connu est sans doute Razer Cortex)

    2. Lorsque je clique sur une option, j'obtiens le texte "Launching Skype... Please wait few seconds." je ne suis pas certain du script correspondant, en effet j'aimerais avoir une attente de 5 secondes (5 0000 miliseconds?) et m'affiche ensuite "Skype is running".

    3. J'aimerais vérifier qu'un programme/processus est en cours de fonctionnement et ainsi ignorer ou lancer le programme si celui ci n'est pas lancé.

    4. Je n'arrive pas à mettre des couleurs spécifique sur un texte. is running = vert; is not running = rouge

    Je vous remercie beaucoup de votre aide.

    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
     
    @echo off
    cls
    title Run and Close Skype
     
    echo ==================================================================
    echo [1]	Run Skype
    echo [2]	Close Skype
    echo [3]	Skype Status (is it running?)
    echo ==================================================================
     
    :Option
    SET /P INPUT="Choose an option:"
    IF /I '%INPUT%'=='1' GOTO Run
    IF /I '%INPUT%'=='2' GOTO Close
    IF /I '%INPUT%'=='3' GOTO Status
    IF /I '%INPUT%'=='Q' GOTO Quit
     
    :Run
    echo.
    echo Launching Skype... Please wait few seconds.
    start "" /b /min /LOW Skype.exe
    ping 192.0.2.2 -n 1 -w 5000>nul 2>nul
    tasklist /FI "IMAGENAME eq Skype.exe" 2>NUL | find /I /N "Skype.exe">NUL
    if "%ERRORLEVEL%"=="0" echo Skype is running.							
    if "%ERRORLEVEL%"=="1" echo Skype is not running.
    echo.
    GOTO Option
     
    :Close
    echo.
    echo Closing Skype... Please wait few seconds.
    taskkill /f /im Skype.exe>NUL
    ping 192.0.2.2 -n 1 -w 2000>nul 2>nul
    tasklist /FI "IMAGENAME eq Skype.exe" 2>NUL | find /I /N "Skype.exe">NUL
    ::If Skype if closed, status is running... problem?
    if "%ERRORLEVEL%"=="0" echo Skype is running.							
    if "%ERRORLEVEL%"=="1" echo Skype is not running.
    echo.
    GOTO Option
     
    :Status
    echo.
    echo Checking Skype status... Please wait few seconds.
    ping 192.0.2.2 -n 1 -w 1000>nul 2>nul
    tasklist /FI "IMAGENAME eq Skype.exe" 2>NUL | find /I /N "Skype.exe">NUL
    if "%ERRORLEVEL%"=="0" echo Skype is running.							
    if "%ERRORLEVEL%"=="1" echo Skype is is not running.
    echo.
    GOTO Option
     
    :Quit
    EXIT

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut

    Inspirez-vous de ce code avec un menu dynamique.
    J'ai ajouté un petit bonus dont la possibilité de tuer à la fois plusieurs et différents processus séparés par un espace :
    Exemple si vous voulez arrêter la calculatrice , Notepad, chrome et Skype
    Vous deviez taper dans le menu de Kill comme ceci :
    Calc.exe Chrome.exe Notepad.exe Skype.exe
    Donc le batch va essayer de les tuer et enregistrer les résultats du "kill" dans un fichier Log
    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
    @Echo off & cls & color 0B
    Mode con cols=72 lines=10
    Set TmpFile=TmpFile.txt
    Set Resultat=KillResult.txt
    If Exist %TmpFile% Del %TmpFile%
    If Exist %Resultat% Del %Resultat%
    :menuLOOP
    Cls & color 0B
    Title Process Starter and Killer by Hackoo 2015
    echo.
    echo.      ==========================Menu============================
    echo.
    for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo.           %%B  %%C
    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] CheckRunning Skype
    Title  CheckRunning Skype ...
    cls & color 0B
    set Process=Skype.exe
    echo Checking if the %Process% is running or not ...
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %Process%"') DO IF %%x == %Process% goto FOUND
    cls & color 0C
    echo Not running
    echo Cliquer sur une touche pour lancer "%Process%"
    pause>nul
    cls & color 0A
    echo Launching Skype... Please wait few seconds.
    start "" /b /min /LOW %Process%
    ping 192.0.2.2 -n 1 -w 5000>nul 2>nul
    goto FIN
    :FOUND
    cls & color 0A
    echo The %Process% is Running
    :FIN
    echo Cliquer sur une touche pour retourner au menu
    pause>nul
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[2] StartMyProcess
    cls & color 0B
    echo.
    Set /p "MyProcess=Enter the process name> "
    echo.
    echo Le processus %MyProcess% est lance ... 
    Start %MyProcess%
    GOTO :menuLOOP
    ::********************************************************************************************
    :menu_[3] KillProcess
    Title Process Killer by Hackoo 2015
    cls & color 0B
    echo.
    echo                What process do you want to kill ?
    echo.
    set/p "process=Enter the name of the process> "
    cls & color 0C
    Title Killing "%process%" ...
    echo.
    echo                       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
    ::*********************************************************************************************
    :KillMyProcess
    Taskkill /IM "%~1" /F >> %TmpFile% 2>&1
    echo ***************************************************************************** >> %TmpFile%
    exit /b 
    ::*********************************************************************************************
    :EOF
    EXIT

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2015
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2015
    Messages : 18
    Points : 23
    Points
    23
    Par défaut
    Bonjour hackoofr.

    Merci beaucoup de votre réponse.
    Avant toute chose, j'aimerais vous dire que j'ai réussi à lancer Skype en me connectant avec les identifiants Skype (ne fonctionne pas avec l'adresse email Microsoft).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    ::Connect to Username, /nosplash
    ::Wait 10 seconds
    ::Display "Connected to Username, or Not running, Type 1 to run
    echo Connecting to username...
    start "" /b /min /LOW Skype.exe /username:username /password:password /nosplash>NUL
    ping 192.0.2.2 -n 1 -w 10000>nul 2>nul
    tasklist /FI "IMAGENAME eq Skype.exe" 2>NUL | find /I /N "Skype.exe">NUL
    if "%ERRORLEVEL%"=="0" echo Connected to Username.							
    if "%ERRORLEVEL%"=="1" echo Skype is not running. Type 1 to run Skype.
    Concernant votre message,
    C'est une excellente idée de me proposer d'enregistrer dans un fichier log, je n'avais pas penser à l'intérêt que ça pourrait avoir, je vous remercie d'avance!

    1. Où sont enregistrés TmpFile.txt et KillResult.txt ? Peut-on choisir l'emplacement ?
    2. Si je comprend bien %Process% équivaut à Skype.exe grâce à set Process=Skype.exe ?
    Puis-je le mettre au début du script comme ceci: je remarque qu'il y a Set et set c'est pareille ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    :: Set Variable
    Set TmpFile=TmpFile.txt
    Set Resultat=KillResult.txt
    Set Process=Skype.exe
    Set ProcessNavigateur1=Firefox.exe
    :: etc etc etc
    Si je comprend bien, je dois annoncer les variables de chaque processus que je souhaite terminer ?


    edit:
    Voici mon fichier txt:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    13-Jun-15 *** 11:57:48.52 
    ERROR: The process "Skype" not found.
    *****************************************************************************
    Merci beaucoup pour cette fonctionnalité!

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut
    Le menu est interactif càd il attend que l'utilisateur qu'il tape le nom du processus exemple dans votre cas il faut entrer le nom skype.exe avec l'extension .exe que vous avez oublié skype

  5. #5
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2015
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2015
    Messages : 18
    Points : 23
    Points
    23
    Par défaut
    Puis-je rajouter une ligne

    echo Voici les programmes disponible dans ce script, veuillez taper le nom complet avec son extension.

    L'utilisation idéale de ce script serait:
    Lorsque je décide de me lancer dans une session de jeu vidéo, je termine l'ensemble des processus windows non nécessaire durant le jeu, je lance le jeu, je termine Explorer.exe MAIS j'ai toujours la possibilité d'avoir la fenêtre de ce script ouvert, afin de contrôler des actions (ouverture de programme, ouverture d'un navigateur, etc etc) un genre de tout en un sans Explorer.exe

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut
    Citation Envoyé par Damien175 Voir le message
    Puis-je rajouter une ligne
    echo Voici les programmes disponible dans ce script, veuillez taper le nom complet avec son extension.
    L'utilisation idéale de ce script serait:
    Lorsque je décide de me lancer dans une session de jeu vidéo, je termine l'ensemble des processus windows non nécessaire durant le jeu, je lance le jeu, je termine Explorer.exe MAIS j'ai toujours la possibilité d'avoir la fenêtre de ce script ouvert, afin de contrôler des actions (ouverture de programme, ouverture d'un navigateur, etc etc) un genre de tout en un sans Explorer.exe
    Vous pouvez ajouter l'extension .exe qui va le prendre en charge le script au niveau de cette ligne et dans ce cas ce n'est pas nécessaire d'ajouter le .exe quand vous tapiez dans la console :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Taskkill /IM "%~1.exe" /F >> %TmpFile% 2>&1
    Oui vous pouvez tuer évidemment Explorer.exe et le batch reste ouvert afin de contrôler des actions (ouverture de programme, ouverture d'un navigateur, etc etc) un genre de tout en un sans Explorer.exe
    Edit
    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
    @Echo off & cls & color 0B
    Mode con cols=72 lines=10
    Set TmpFile=TmpFile.txt
    Set Resultat=KillResult.txt
    If Exist %TmpFile% Del %TmpFile%
    If Exist %Resultat% Del %Resultat%
    :menuLOOP
    Cls & color 0B
    Title Process Starter and Killer by Hackoo 2015
    echo.
    echo.      ==========================Menu============================
    echo.
    for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo.           %%B  %%C
    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] CheckRunning Skype
    Title  CheckRunning Skype ...
    cls & color 0B
    set Process=Skype.exe
    echo Checking if the %Process% is running or not ...
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %Process%"') DO IF %%x == %Process% goto FOUND
    cls & color 0C
    echo Not running
    echo Cliquer sur une touche pour lancer "%Process%"
    pause>nul
    cls & color 0A
    echo Launching Skype... Please wait few seconds.
    start "" /b /min /LOW %Process%
    ping 192.0.2.2 -n 1 -w 5000>nul 2>nul
    goto FIN
    :FOUND
    cls & color 0A
    echo The %Process% is Running
    :FIN
    echo Cliquer sur une touche pour retourner au menu
    pause>nul
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[2] StartMyProcess
    cls & color 0B
    echo.
    Set /p "MyProcess=Enter the process name without extension> "
    echo.
    echo Le processus %MyProcess% est lance ... 
    Start %MyProcess%.exe
    GOTO :menuLOOP
    ::********************************************************************************************
    :menu_[3] KillProcess
    Title Process Killer by Hackoo 2015
    cls & color 0B
    echo.
    echo                What process do you want to kill ?
    echo.
    ::set/p "process=Enter the name of the process without extension> "
    :: ici vous pouvez ajouter dans la variable Process les processus sans extensions juste séparés par un espace
    set Process=Calc Chrome Notepad Skype
    cls & color 0C
    Title Killing "%process%" ...
    echo.
    echo                       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
    ::*********************************************************************************************
    :KillMyProcess
    Taskkill /IM "%~1.exe" /F >> %TmpFile% 2>&1
    echo ***************************************************************************** >> %TmpFile%
    exit /b 
    ::*********************************************************************************************
    :EOF
    EXIT
    N'oubliez surtout mes +1

  7. #7
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2015
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2015
    Messages : 18
    Points : 23
    Points
    23
    Par défaut
    Bonjour.

    Excusez moi je n'avais pas compris le +1 je pensais que c'était juste un pouce levé
    C'est corrigé.

    J'ai un peu de mal avec ce script.
    Préalablement Skype ne fonctionne pas,
    - Checkrunning
    - Si ne fonctionne pas, AUTO- Start Skype avec les identifiants
    - Checkrunning
    - Annonce: Connected to Pseudo
    - AUTO- Direction vers le menu.

    NB:
    Je suis pas sûr pour le set SkypeLogin...
    Il me manque une étape mais je sais pas où le mettre, on check, si ça fonctionne pas, on lance avec les identifiants, on affiche que c'est connecté.

    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
     
    set SkypeUsername=Username
    set SkypePassword=Password
    set SkypeLogin=/username:%SkypeUsername% /password:%SkypePassword% /nosplash
     
    :menu_[4] Connect to %SkypeUsername%
    Title Connecting to %SkypeUsername%
    cls & color 0B
    echo.
    echo Checking if the %Process% is running or not...
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %Process%"') DO IF %%x == %Process% goto FOUND
    start "" /b /min /LOW %Process% /username:%SkypeUsername% /password:%SkypePassword% /nosplash>NUL
    ping 192.0.2.2 -n 1 -w 5000>nul 2>nul
    goto FIN
    :FOUND
    cls & color 0A
    echo The %Process% is running and connected to %SkypeUsername%
    GOTO:menuLOOP

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut

    Dans le :menu_[4] AutoConnecting with Skype
    Changer juste les variables :
    set SkypeUsername=nom utilisateur de skype
    set SkypePassword=password skype
    Par les vôtres puis tester
    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
    @Echo off & cls & color 0B
    Mode con cols=72 lines=10
    Set TmpFile=TmpFile.txt
    Set Resultat=KillResult.txt
    If Exist %TmpFile% Del %TmpFile%
    If Exist %Resultat% Del %Resultat%
    :menuLOOP
    Cls & color 0B
    Title Process Starter and Killer by Hackoo 2015
    echo.
    echo.      ==========================Menu============================
    echo.
    for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo.           %%B  %%C
    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] CheckRunning Skype
    Title  CheckRunning Skype ...
    cls & color 0B
    set Process=Skype.exe
    echo Checking if the %Process% is running or not ...
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %Process%"') DO IF %%x == %Process% goto FOUND
    cls & color 0C
    echo Not running
    echo Cliquer sur une touche pour lancer "%Process%"
    pause>nul
    cls & color 0A
    echo Launching Skype... Please wait few seconds.
    start "" /b /min /LOW %Process%
    ping 192.0.2.2 -n 1 -w 3000>nul 2>nul
    goto FIN
    :FOUND
    cls & color 0A
    echo The %Process% is Running
    :FIN
    echo Cliquer sur une touche pour retourner au menu
    pause>nul
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[2] StartMyProcess
    cls & color 0B
    echo.
    Set /p "MyProcess=Enter the process name without extension> "
    echo.
    echo Le processus %MyProcess% est lance ... 
    Start %MyProcess%.exe
    GOTO :menuLOOP
    ::********************************************************************************************
    :menu_[3] KillProcess
    Title Process Killer by Hackoo 2015
    cls & color 0B
    echo.
    echo                What process do you want to kill ?
    echo.
    set/p "process=Enter the name of the process without extension> "
    cls & color 0C
    Title Killing "%process%" ...
    echo.
    echo                       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_[4] AutoConnecting with Skype
    set SkypeUsername=nom utilisateur de skype
    set SkypePassword=password skype
    set Process=Skype.exe
    Title Connecting to %SkypeUsername%
    cls & color 0B
    echo.
    echo Checking if the %Process% is running or not...
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %Process%"') DO IF %%x == %Process% goto FOUND
    start "" /b /min /LOW %Process% /username:%SkypeUsername% /password:%SkypePassword% /nosplash>NUL
    cls & color 0C
    echo Not running
    ping 192.0.2.2 -n 1 -w 3000>nul 2>nul
    echo Cliquer sur une touche pour lancer "%Process%"
    pause>nul
    goto FIN
    :FOUND
    cls & color 0A
    echo The %Process% is running and connected to %SkypeUsername%
    :FIN
    echo Tapez sur touche pour retourner au menu principal
    pause>nul
    GOTO :menuLOOP
    ::*********************************************************************************************
    :KillMyProcess
    Taskkill /IM "%~1.exe" /F >> %TmpFile% 2>&1
    echo ***************************************************************************** >> %TmpFile%
    exit /b 
    ::*********************************************************************************************
    :EOF
    EXIT

  9. #9
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2015
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2015
    Messages : 18
    Points : 23
    Points
    23
    Par défaut
    Avec mes identifiants ça fonctionne sans problème, merci beaucoup.
    mais ne peut-on pas raccourcir avec :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    set SkypeLogin=/username:%SkypeUsername% /password:%SkypePassword%
    
    ::old
    start "" /b /min /LOW %Process% /username:%SkypeUsername% /password:%SkypePassword% /nosplash>NUL
    afin d'obtenir:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    start "" /b /min /LOW %Process% $SkypeLogin$ /nosplash>NUL
    Donc avec votre code, il est préférable de mettre les Set sous les fonctions ?


    Au niveau du log.txt
    Pourriez vous m'orienter afin d'avoir qqchose comme:

    ----------------------------------
    - Navigateur Internet
    13-Jun-15 *** 13:50:25
    ----------------------------------
    SUCCESS: The process "chrome.exe" with PID XXXX has been terminated.
    SUCCESS: The process "firefox.exe" with PID XXXX has been terminated.
    SUCCESS: The process "spartan_edge.exe" with PID XXXX has been terminated.

    ----------------------------------
    - Communication
    13-Jun-15 *** 13:52:10 au lieu de 13-Jun-15 *** 13:52:10.56
    ----------------------------------
    SUCCESS: The process "skype.exe" with PID XXXX has been terminated.
    SUCCESS: The process "teamspeakClient.exe" with PID XXXX has been terminated.
    SUCCESS: The process "teamspeakServer.exe" with PID XXXX has been terminated.

    En terminant, plusieurs processus en même temps, j'aimerais que se soit plus lisible.

    "chrome.exe" n'est pas installé sur mon ordinateur, j'obtiens ERROR: The process "Chrome.exe" not found.
    je suppose que si mon ami qui utilise le script et possède "chrome.exe" il n'y aura pas d'erreur, il aura bien "has been terminated.", right?
    C'est donc une erreur normale pour ma part ?
    Comment distingue t-on "not found" = n'est pas installé et "not running" = est installé, mais n'est pas lancé ? dans le log.txt

    NB.
    Je regarde le script de votre précédent message, j'éditerais ce message si j'ai un problème.

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut [Bat] AutoConnecting to Skype
    Testez en premier lieu ce batch sans l'intégrer dans le menu, alors si ça marche chez vous ? vous pouvez ensuite essayer de l'intégrer au programme principal
    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
    @echo off
    set SkypeUsername=UserName
    Title AutoConnecting to Skype with this %SkypeUsername%
    set SkypePassword=Password
    set Process=Skype.exe
    set SkypeLogin=/username:%SkypeUsername% /password:%SkypePassword% /nosplash
    cls & color 0B
    echo.
    echo Checking if the %Process% is running or not...
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %Process%"') DO IF %%x == %Process% goto FOUND
    start "" /b /min /LOW %Process% %SkypeLogin% >NUL
    echo Connecting to Skype with %SkypeUsername%
    ping 192.0.2.2 -n 1 -w 3000>nul 2>nul
    goto FIN
    :FOUND
    cls & color 0A
    echo The %Process% is running and connected to %SkypeUsername%
    :FIN
    echo Appuyez sur touche pour quitter ce batch
    pause>Nul
    Exit

  11. #11
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2015
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2015
    Messages : 18
    Points : 23
    Points
    23
    Par défaut
    Merci beaucoup,
    Votre script fonctionne avec charme.

    Si je comprend bien, j'écris se que je souhaitais voir au début sur mon écran, quand je choisis l'option AutoConnecting

    AutoConnecting to Skype with Username

    Skype is running, AutoConnecting...
    or
    Skype is not running, Launching and AutoConnecting to Username...
    Connected to Skype with Username
    Appuyer sur une touche pour aller au menu principale

    ###
    Lorsque Skype fonctionne mais n'est pas connecté à un compte, le script ne fonctionne pas.
    J'obtiens juste le message "Skype is running and connected to Username
    sans que Skype soit réellement connecté au compte.

    N'est il pas mieux de forcer quoi qu'il soit Skype, pour ensuite le relancer avec les identifiants ?

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut

    En lisant ceci : La ligne de commande de skype
    On peut tuer le processus Skype par cette commande :
    Code BAT : Sélectionner tout - Visualiser dans une fenêtre à part
    Skype.exe /Shutdown
    Donc il préférable de tuer toutes les instances de skype avant d'être connecté avec un profil d’utilisateur précis comme dans ce code :
    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
    @echo off
    Cls & Color 0C
    set SkypeUsername=UserName
    Title AutoConnecting to Skype with this %SkypeUsername%
    set SkypePassword=myPassword
    set Process=Skype.exe
    echo Killing any instance of "%Process%" 
    %process% /Shutdown
    pause
    set SkypeLogin=/username:%SkypeUsername% /password:%SkypePassword% /nosplash /minimized
    cls & color 0B
    echo.
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %Process%"') DO IF %%x == %Process% goto FOUND
    start "" /b /min /LOW %Process% %SkypeLogin% >NUL
    echo Connecting to Skype with %SkypeUsername%
    ping 192.0.2.2 -n 1 -w 3000>nul 2>nul
    goto FIN
    :FOUND
    cls & color 0A
    echo The %Process% is running and connected to %SkypeUsername%
    :FIN
    echo Appuyez sur touche pour quitter ce batch
    pause>Nul
    Exit

  13. #13
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2015
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2015
    Messages : 18
    Points : 23
    Points
    23
    Par défaut
    Bonjour,

    Oui j'avais déjà vu ce document en cherchant à me connecter avec des identifiants.
    Le script fonctionne à merveille, merci beaucoup.

    J'ai quelques questions supplémentaires si ça vous dérange pas.
    1. J'aimerais mettre les processus à terminer sous une catégorie:
    - [1]Navigateur: Chrome, IE, Firefox, Spartan, etc..
    - [2]Office: Word, Excel, etc etc...
    - [3]Communication: Skype, TeamSpeak, Mumble, etc...
    - [4]Tous: Tous les processus

    Je lance mon script et pour la commande :KillProcess je dois choisir une option,
    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
     
    Title Process Killer by Hackoo 2015
    cls & color 0B
    echo.
    echo                What process category do you want to kill ?
    echo.
    set/p "Choosen=Enter an option to kill > "
    set Navigateur=Chrome Firefox Spartan InternetExplorer
    set Office=Word Excel
    set Communication=Skype TeamspeakClient TeamspeakServer Mumble
    set Tous=goto :Navigateur :Office :Communication
     
    cls & color 0C
    Title Killing "%process%" ...
    echo.
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %Process%"') DO IF %%x == %Process% goto FOUND
    cls & color 0C
    echo %Choosen% is not running.
    echo.
    echo %date% *** %time% >> %TmpFile%
    For %%a in (%Choosen%) Do Call :KillMyProcess %%a
    Cmd /U /C Type %TmpFile% > %Resultat%
    Start %Resultat%
    GOTO :menuLOOP



    Grâce à ton aide,
    J'ai pu faire ce script, est-il possible de l'optimiser ?
    Des remarques sur le code, notamment la syntaxe et autres ?

    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
     
    @Echo off & cls & color 0B
    Mode con cols=72 lines=10
     
    Set Title=Skype Starter and Killer
    Set TmpFile=TmpFile.txt
    Set Resultat=KillResult.txt
    If Exist %TmpFile% Del %TmpFile%
    If Exist %Resultat% Del %Resultat%
     
    set SkypeExe=Skype.exe
    set SkypeName=Skype
    set SkypeUsername=Username
    set SkypePassword=Password
    set SkypeLogin=/username:%SkypeUsername% /password:%SkypePassword% /nosplash /minimized
    ::set Available=Calc Chrome Notepad Skype
    ::*******************************************************************************************
    :menulOOP
    Cls & color 0B
    Title %Title%
    echo.
    echo.      ==========================Menu============================
    echo.
    for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo.           %%B  %%C
    echo.
    echo.      ==========================================================
    set option=
    echo. & set /p option=Choose an option or hit ENTER to quit: || GOTO :EOF
    echo. & call :menu_[%option%]
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[1] Skype Status AND AutoConnect question
    Title  %SkypeName% Status...
    cls & color 0B
    echo Checking if %SkypeName% is running or not...
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %SkypeExe%"') DO IF %%x == %SkypeExe% goto FOUND
    cls & color 0C
    echo %SkypeName% is not running.
    echo Cliquer sur une touche pour lancer "%SkypeName%"
    pause>nul
    cls & color 0A
    echo Launching %SkypeName%...
    start "" /b /min /LOW %SkypeExe% /nosplash /minimized >nul
    ping 192.0.2.2 -n 1 -w 5000>nul 2>nul
    goto FOUND
     
    :CHOICE
    set /P Want2Connect=Do you want to be connected to %SkypeUsername% [Y/N]?
    if /I "%Want2Connect%" EQU "Y" goto :AutoConnect
    if /I "%Want2Connect%" EQU "N" goto :FIN
    goto :choice
     
    :AutoConnect
    Cls & Color 0C
    Title AutoConnecting to %SkypeName% with %SkypeUsername%
    echo Killing any instance of %SkypeName%
    %SkypeExe% /Shutdown
    pause>nul
    echo.
    cls & color 0B
    echo.
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %SkypeExe%"') DO IF %%x == %SkypeExe% goto FOUND
    start "" /b /min /LOW %SkypeExe% %SkypeLogin% >nul
    echo Connecting to %SkypeName% with %SkypeUsername%
    ping 192.0.2.2 -n 1 -w 3000>nul 2>nul
    goto CONNECTED
     
    :CONNECTED
    cls & color 0A
    echo You are now connected to %SkypeUsername%
    pause>nul
    GOTO:menuLOOP
     
    :FOUND
    cls & color 0A
    echo %SkypeName% is running.
    goto CHOICE
     
    :FIN
    echo Cliquer sur une touche pour retourner au menu
    pause>nul
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[2] StartMyProcess
    Title Start Available programs
    cls & color 0B
    echo.
    echo                Choose which program you want to run ?
    echo.
    Set /p "RunProcess=Write program name to run without extension> "
    set Available=Calc Chrome Notepad Skype
    echo Programs who can be started: %Available%
    echo.
    cls & color 0A
    Start "" /b /min /LOW %RunProcess%.exe>nul
    echo %RunProcess% is launched.
    pause>nul
    GOTO :menuLOOP
    ::********************************************************************************************
    :menu_[3] KillMyProcess
    Title Kill Available programs
    cls & color 0B
    echo.
    echo                Choose which program you want to kill ?
    echo.
    set/p "KillProcess=Write program name to kill without extension> "
    set Available=Calc Chrome Notepad Skype
    echo Programs who can be killed: %Available%
    cls & color 0C
    Title Killing "%KillProcess%" ...
    echo.
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %KillProcess%"') DO IF %%x == %KillProcess% goto FOUND
    cls & color 0C
    echo %KillProcess% is not running.
    echo.
    echo %date% *** %time% >> %TmpFile%
    For %%a in (%KillProcess%) Do Call :KillMyProcess %%a
    Cmd /U /C Type %TmpFile% > %Resultat%
    Start %Resultat%
    GOTO :menuLOOP
    ::*********************************************************************************************
    :KillMyProcess
    Taskkill /IM "%~1.exe" /F >> %TmpFile% 2>&1 >nul
    echo ***************************************************************************** >> %TmpFile%
    exit /b 
    ::*********************************************************************************************
    :EOF
    EXIT

    Problem:
    set Available=Calc Chrome Notepad Skype
    echo Programs who can be killed: %Available%

    Ne n'affiche pas la liste des programmes..

Discussions similaires

  1. [FAQ] Comment programmer une pause dans le code autrement ?
    Par Invité dans le forum Vos Contributions VBScript
    Réponses: 0
    Dernier message: 18/08/2013, 22h07
  2. Quitter un programme à tout moment à l'appuie d'une touche
    Par Bash01 dans le forum Général Java
    Réponses: 5
    Dernier message: 19/07/2011, 14h25
  3. Réponses: 3
    Dernier message: 01/05/2007, 13h03
  4. [Task] Lancer un programme à une date donnée ?
    Par jsl1 dans le forum API standards et tierces
    Réponses: 3
    Dernier message: 27/01/2006, 13h44
  5. Réponses: 2
    Dernier message: 04/06/2004, 11h36

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