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 :

Problème variable %path% [Batch]


Sujet :

Scripts/Batch

  1. #1
    Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Décembre 2018
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2018
    Messages : 48
    Points : 40
    Points
    40
    Par défaut Problème variable %path%
    Bonjour à tous.
    J'ai un script .bat qui permet de lancer plusieurs tâches (lancement d'autres .bat pour installation de logiciels et autres...) [merci à ericlm128]
    Pour le moment, le script et le dossier complet doivent être placés à la racine de C:\ pour fonctionner correctement.
    Je souhaiterai effectuer une modification.
    Je voudrais que le script puisse fonctionner même si le dossier n'est pas placé à la racine de C:\
    Pour cela, je me suis dit qu'il fallait que je définisse une variable path.
    Code BATCH : Sélectionner tout - Visualiser dans une fenêtre à part
    set path=%path%;C:\Users\%username%\desktop\PrepaPC
    Script "Start.bat"
    Code BATCH : 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
    @echo OFF
    setlocal ENABLEDELAYEDEXPANSION
    cls
    color E
    REM Initialize
    for /L %%I in (1,1,2) do set ITEM%%I=[ ]
     
    :Boucle
    cls
    echo ##############################
    echo #~~ CONFIGURATION DE POSTE ~~#
    echo ##############################
    echo.
    echo Choisissez la marque de votre PC :
    echo.
    echo %ITEM1% 01. Autres PC
    echo %ITEM2% 02. Lenovo
    echo.
    echo Taper "Q" pour Quitter
    echo Taper "1" ou "2" pour faire votre choix et appuyer sur "ENTER"
    echo Taper "R" pour valider votre choix et appuyer sur "ENTER"
    echo Taper "X" pour afficher le fichier de note de versions
     
    set WhichItem=
    set /P WhichItem=Faites votre choix et appuyer sur "ENTER" : 
     
    if not defined WhichItem goto Boucle
    if /I "%WhichItem%"=="Q" goto exit
    if /I "%WhichItem%"=="R" goto RunOptions
    if /I "%WhichItem%"=="X" goto item3
     
    set /A WhichItem=%WhichItem%
     
    for /L %%I in (1,1,2) do if "%%I"=="%WhichItem%" (
    	if "!Item%WhichItem%!"=="[X]" (
    		set Item%WhichItem%=[ ]
    	) else (
    		set Item%WhichItem%=[X]
    	)
    )
    goto Boucle
     
    :RunOptions
    for /L %%I in (1,1,2) do if "!Item%%I!"=="[X]" call :Item%%I
    pause
    goto :EOF
     
    :item1
    REM Autres PC
    call C:\PrepaPC\ConfigPC\Menu\Batch#1\#StartPC#.bat
    goto :EOF
     
    :item2
    REM Lenovo
    call C:\PrepaPC\ConfigPC\Menu\Batch#1\#StartLenovo#.bat
    goto :EOF
     
    :item3
    REM Note de versions
    start notepad C:\PrepaPC\Version.txt
    goto :EOF
     
    :exit
    exit

    Cependant, j'obtiens une erreur une fois ma sélection faite.
    La fenêtre CMD m'affiche une erreur :
    Nom : CMD_Error.PNG
Affichages : 484
Taille : 17,3 Ko

    Je ne vois pas d'où peut venir mon erreur.
    Merci d'avance pour votre aide.

  2. #2
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Bonjour,

    Déjà pour commencer la photo ne correspond pas au script que tu as posté, merci de poster le script correspondant.

    Ensuite tu utilises mal la variable %PATH% je pense qu'une banale variable fera l'affaire, enfin tout sauf %PATH%, par exemple :

    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    set chemin=C:\Users\%username%\desktop\PrepaPC

  3. #3
    Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Décembre 2018
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2018
    Messages : 48
    Points : 40
    Points
    40
    Par défaut
    Bonjour barnabe0057,

    Effectivement je n'avais pas posté le bon script.
    J'ai corrigé mon erreur sur mon post.

    Je vais faire un test avec ton explication.

    Merci bien

  4. #4
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Je ne vois rien dans ce script qui pourrait causer l'erreur de la photo, je pense que le problème se situe au niveau du script #StartLenovo#.bat

  5. #5
    Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Décembre 2018
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2018
    Messages : 48
    Points : 40
    Points
    40
    Par défaut
    Ok, ok.
    Ci dessous le script #StartLenovo#.bat

    Code BATCH : 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
    @echo off
    setlocal ENABLEDELAYEDEXPANSION
    set path=%path%;C:\Users\%username%\desktop\PrepaPC
    color E
    for /L %%I in (1,1,5) do set ITEM%%I=[ ]
     
    :Boucle
    cls
    echo ###############################
    echo #~~ CONFIGURATION PC LENOVO ~~#
    echo ###############################
    echo.
    echo Quel(s) programme(s) voulez-vous executer ?
    echo.
    echo %ITEM1% 01. Installation d'applications
    echo %ITEM2% 02. Configuration Explorer.exe
    echo %ITEM3% 03. Ajout de fonctionnalites
    echo %ITEM4% 04. Finalisation
    echo %ITEM5% 05. Tous les programmes
    echo.
    echo Taper P pour revenir au menu precedent
    echo Taper Q pour quitter le programme
    echo Taper R pour lancer l'installation
     
    set WhichItem=
    set /P WhichItem=Faites votre choix et appuyer sur ENTER : 
     
    if not defined WhichItem goto Boucle
    if /I "%WhichItem%"=="P" goto item6
    if /I "%WhichItem%"=="Q" goto exit
    if /I "%WhichItem%"=="R" goto RunOptions
     
    set /A WhichItem=%WhichItem%
     
    for /L %%I in (1,1,5) do if "%%I"=="%WhichItem%" (
    	if "!Item%WhichItem%!"=="[X]" (
    		set Item%WhichItem%=[ ]
    	) else (
    		set Item%WhichItem%=[X]
    	)
    )
    goto Boucle
     
    :RunOptions
    for /L %%I in (1,1,5) do if "!Item%%I!"=="[X]" call :Item%%I
    pause
    goto :EOF
     
    :item1
    REM Installation d'applications
    call %path%\ConfigPC\Menu\Batch#2\#1AppsL#.bat
    goto :EOF
     
    :item2
    REM Configuration Explorer.exe
    call %path%\ConfigPC\Menu\Batch#2\#2ExplorerL#.bat
    goto :EOF
     
    :item3
    REM Ajout de fonctionnalites
    call %path%\ConfigPC\Menu\Batch#2\#3FonctionsL#.bat
    goto :EOF
     
    :item4
    REM Finalisation
    call %path%\ConfigPC\Menu\Batch#2\#4FinalisationL#.bat
    goto :EOF
     
    :item5
    REM Tous les programmes
    call %path%\ConfigPC\Menu\Batch#2\#5AllProgramsL#.bat
    goto :EOF
     
    :item6
    REM %path%\Start.bat
    call %path%\Start.bat
    goto :EOF
     
    :exit
    exit

    Merci pour ton aide

  6. #6
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Essaie comme ça :

    Code Batch : 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
    setlocal ENABLEDELAYEDEXPANSION
    set chemin=C:\Users\%username%\desktop\PrepaPC
    color E
    for /L %%I in (1,1,5) do set ITEM%%I=[ ]
     
    :Boucle
    cls
    echo ###############################
    echo #~~ CONFIGURATION PC LENOVO ~~#
    echo ###############################
    echo.
    echo Quel(s) programme(s) voulez-vous executer ?
    echo.
    echo %ITEM1% 01. Installation d'applications
    echo %ITEM2% 02. Configuration Explorer.exe
    echo %ITEM3% 03. Ajout de fonctionnalites
    echo %ITEM4% 04. Finalisation
    echo %ITEM5% 05. Tous les programmes
    echo.
    echo Taper P pour revenir au menu precedent
    echo Taper Q pour quitter le programme
    echo Taper R pour lancer l'installation
     
    set WhichItem=
    set /P WhichItem=Faites votre choix et appuyer sur ENTER : 
     
    if not defined WhichItem goto Boucle
    if /I "%WhichItem%"=="P" goto item6
    if /I "%WhichItem%"=="Q" exit
    if /I "%WhichItem%"=="R" goto RunOptions
     
    set /A WhichItem=%WhichItem%
     
    for /L %%I in (1,1,5) do if "%%I"=="%WhichItem%" (
    	if "!Item%WhichItem%!"=="[X]" (
    		set Item%WhichItem%=[ ]
    	) else (
    		set Item%WhichItem%=[X]
    	)
    )
    goto Boucle
     
    :RunOptions
    for /L %%I in (1,1,5) do if "!Item%%I!"=="[X]" call :Item%%I
    pause
    goto :EOF
     
    :item1
    REM Installation d'applications
    call %chemin%\ConfigPC\Menu\Batch#2\#1AppsL#.bat
    goto :EOF
     
    :item2
    REM Configuration Explorer.exe
    call %chemin%\ConfigPC\Menu\Batch#2\#2ExplorerL#.bat
    goto :EOF
     
    :item3
    REM Ajout de fonctionnalites
    call %chemin%\ConfigPC\Menu\Batch#2\#3FonctionsL#.bat
    goto :EOF
     
    :item4
    REM Finalisation
    call %chemin%\ConfigPC\Menu\Batch#2\#4FinalisationL#.bat
    goto :EOF
     
    :item5
    REM Tous les programmes
    call %chemin%\ConfigPC\Menu\Batch#2\#5AllProgramsL#.bat
    goto :EOF
     
    :item6
    REM %chemin%\Start.bat
    call %chemin%\Start.bat
    goto :EOF

  7. #7
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    On peut simplifier un peu comme ceci :

    Code Batch : 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
    setlocal ENABLEDELAYEDEXPANSION
    set chemin=C:\Users\%username%\desktop\PrepaPC
    color E
    for /L %%I in (1,1,5) do set ITEM%%I=[ ]
     
    :Boucle
    cls
    echo ###############################
    echo #~~ CONFIGURATION PC LENOVO ~~#
    echo ###############################
    echo.
    echo Quel(s) programme(s) voulez-vous executer ?
    echo.
    echo %ITEM1% 01. Installation d'applications
    echo %ITEM2% 02. Configuration Explorer.exe
    echo %ITEM3% 03. Ajout de fonctionnalites
    echo %ITEM4% 04. Finalisation
    echo %ITEM5% 05. Tous les programmes
    echo.
    echo Taper P pour revenir au menu precedent
    echo Taper Q pour quitter le programme
    echo Taper R pour lancer l'installation
     
    set WhichItem=
    set /P WhichItem=Faites votre choix et appuyer sur ENTER : 
     
    if not defined WhichItem goto Boucle
    if /I "%WhichItem%"=="P" goto item6
    if /I "%WhichItem%"=="Q" exit
    if /I "%WhichItem%"=="R" goto RunOptions
     
    set /A WhichItem=%WhichItem%
     
    for /L %%I in (1,1,5) do if "%%I"=="%WhichItem%" (
    	if "!Item%WhichItem%!"=="[X]" (
    		set Item%WhichItem%=[ ]
    	) else (
    		set Item%WhichItem%=[X]
    	)
    )
    goto Boucle
     
    :RunOptions
    pushd "%chemin%\ConfigPC\Menu\Batch#2"
    for /L %%I in (1,1,5) do if "!Item%%I!"=="[X]" call :Item%%I
    popd
    pause
    goto :EOF
     
    :item1
    REM Installation d'applications
    call #1AppsL#.bat
    goto :EOF
     
    :item2
    REM Configuration Explorer.exe
    call #2ExplorerL#.bat
    goto :EOF
     
    :item3
    REM Ajout de fonctionnalites
    call #3FonctionsL#.bat
    goto :EOF
     
    :item4
    REM Finalisation
    call #4FinalisationL#.bat
    goto :EOF
     
    :item5
    REM Tous les programmes
    call #5AllProgramsL#.bat
    goto :EOF
     
    :item6
    REM %chemin%\Start.bat
    call %chemin%\Start.bat
    goto :EOF

  8. #8
    Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Décembre 2018
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2018
    Messages : 48
    Points : 40
    Points
    40
    Par défaut
    Merci pour ton aide barnabe0057.

    Tout fonctionne.
    Je comprends mieux la fonction pushd.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. JDK bien installé mais problème avec la variable PATH
    Par abysr dans le forum EDI et Outils pour Java
    Réponses: 4
    Dernier message: 27/10/2014, 18h15
  2. Modifier la variable PATH
    Par al85 dans le forum Linux
    Réponses: 4
    Dernier message: 07/11/2008, 16h14
  3. [Rave report 5.1.3][delphi 7] Probléme variable PIVar
    Par GILLESKLEIN dans le forum Rave
    Réponses: 2
    Dernier message: 05/02/2005, 15h27
  4. Ajouter des chemins dans la variable PATH
    Par Righetto Dominique dans le forum Linux
    Réponses: 7
    Dernier message: 21/03/2004, 17h38
  5. problème variable extern
    Par HeKaz dans le forum C
    Réponses: 14
    Dernier message: 08/01/2003, 01h44

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