Existe-t-il un outil de ligne de commande qui peut être utilisé pour modifier des variables d'environnement dans Windows?
Ce serait bien si c'était un outil intelligent, par exemple:
Et le dernier mais pas le moindre - Je veux que mes changements persistent entre sessions Un ensemble simple est hors de question ...
Il y a très bel outil d'interface graphique pour cet appelé éditeur de chemin et j'ai besoin de quelque chose comme ça, mais pour la ligne de commande.
Pour le programme actuel, il y a path
:
Affiche ou définit un chemin de recherche pour les fichiers exécutables.
PATH [[drive:]path[;...][;%PATH%] PATH ;
Taper
PATH ;
Pour effacer tous les paramètres de recherche et directecmd.exe
Pour rechercher uniquement dans le répertoire actuel.Type
PATH
sans paramètres pour afficher le chemin actuel. Y compris%PATH%
Dans le nouveau chemin de chemin provoque l'annexe de l'ancien chemin d'accès au nouveau paramètre.
Cependant, c'est à peu près la même chose que set PATH
.
Pour les variables d'environnement pour persister, vous devez modifier le registre ou utiliser setx
.
Je viens de découvrir la possibilité d'autoriser les utilisateurs à exécuter la boîte de dialogue Modifier les variables d'environnement sans privilèges élevés.
Dans le menu Démarrer, exécutez ce qui suit:
rundll32 sysdm.cpl,EditEnvironmentVariables
Vous voudrez peut-être vérifier en chemin de la collection GTools: http://www.p-nand-q.com/gtools.html
Il fournit un ensemble de commandes pour la commande promt comme
pathed /APPEND %CD% /USER
ajouter le chemin actuel par exemple. Je n'ai pas vraiment vérifié pour être honnête, car je vais totalement bien d'utiliser une interface graphique.
D'autres options sont:
/MACHINE: print machine PATH
/USER: print user PATH
/ADD: add variable at the head
/APPEND: add variable at the tail
/REMOVE: remove path / index
/SLIM: strip duplicate vars
/ENV: environment variable, defaults to PATH
Avec lesquels de la même collection, vous avez eu de bons outils, je suppose. Qui "localise des fichiers exécutables sur le chemin".
/EXTENSION: search for extension , can be a ; separated list
/DIR: add directory , can be a ; separated list
/RECURSIVE: search directories recursively
/SINGLE: stop after the first find result
/ENV: environment variable, defaults to PATH
FILE {FILE}: one or more files to find
Source: http://op111.net/82/
parcourir
(Help Set)
J'ai écrit un ensemble de scripts de lot pour cela. addpath.bat ajoute des éléments au chemin, RMPath.Bat supprime les éléments du chemin et LPATH.BAT vise simplement le chemin. Mais alors j'avais besoin de scripts de soutien, donc il y a aussi chkpath.bat.
Il a fini par ne pas être trivial et requis TR.EXE et CAT.EXE, quelques utilitaires de style UNIX. La raison pour laquelle ce n'est pas trivial: pas de backticules dans cmd.exe (bien que vous puissiez utiliser des boucles pour cela) et des noms abrégés par rapport aux noms longs.
addpath.bat:
@echo off
setlocal
set cwd=%~dps0
goto testit
:loopy
call %cwd%chkpath "%~1"
if %errorlevel%==2 (
set path=%path%;%~1
)
shift
:testit
if not _%1==_ goto loopy
call %cwd%lpath.bat
endlocal & set path=%path%
Chkpath.bat:
@echo off
goto START
-------------------------------------------------------
chkpath.bat
checks path for existence of the given segment.
Returns 1 if present, 2 if not present, 0 if not checked.
The matching and checking complicated by case sensitivity and "short pathnames".
created sometime in 2003 and lovingly maintained since then.
-------------------------------------------------------
:START
setlocal enabledelayedExpansion
set rc=0
set cwd=%~dps0
set curdrive=%~d0
set tr=%curdrive%\bin\tr.exe
set regexe=%windir%\system32\reg.exe
if _%1==_ goto Usage
@REM convert arg 1 to a fully-qualified, short path name,
@REM and then convert to uppercase.
set toupper=%~fs1
call :ToUpper
set tocheck=%toupper%
if not _%TEMP%==_ goto GotTemp
call :gettemp
:GotTemp
set d=%DATE:~4%
set stamp=%d:~6%%d:~3,2%%d:~0,2%%TIME::=%
set d=
set tempfile1=%TEMP%\chkpath1-%stamp%.tmp
echo %path% | %tr% ; \n > %tempfile1%
@REM check each element in the path for the match:
for /f "delims=^" %%I in (%tempfile1%) do (
if !rc!==0 (
call :CheckElt "%%I"
)
)
if %rc%==0 set rc=2
goto END
--------------------------------------------
* checkelt
*
* check one element in the path to see if it is the same
* as the TOCHECK string. The element is first canonicalized.
*
:CheckElt
@REM remove surrounding quotes
set ERF=%1
if [x%ERF%]==[x] goto CheckEltDone
@REM convert to fully-qualified, short paths, uppercase
set TOUPPER=%~fs1%
call :ToUpper
if _%TOCHECK% == _%TOUPPER% set rc=1
:CheckEltDone
goto:EOF
--------------------------------------------
--------------------------------------------
* backtick
*
* invoke a command and return the result as a string.
* This is like backtick in csh or bash.
* To call, set variable BACKTICK to the command to be run.
* The result will be stored in the env variable of the same name.
*
:backtick
FOR /F "usebackq delims=" %%i IN (`%backtick%`) DO (
SET backtick=%%i
)
goto backtick_done
:backtick_none
SET backtick=nothing to exec
:backtick_done
goto:EOF
--------------------------------------------
--------------------------------------------
* gettemp
*
* get the temporary directory, as stored in the registry.
* Relies on backtick.
*
* The result set TEMP.
*
:gettemp
set regkey=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
set regvalname=Local AppData
set backtick=%regexe% query "%regkey%" /v "%regvalname%"
call :backtick
for /f "tokens=4" %%a in ("%backtick%") do (
set temp=%%a
)
goto:EOF
--------------------------------------------
--------------------------------------------
* ToUpper
*
* Convert a string to all uppercase.
* To call, set variable TOUPPER to the thing to be converted.
* The result will be stored in the env variable of the same name.
*
:ToUpper
FOR /F "usebackq delims=" %%I IN (`echo %toupper% ^| %tr% a-z A-Z`) DO (
SET toupper=%%I
)
goto:EOF
--------------------------------------------
--------------------------------------------
:CleanUp
if _%tempfile1%==_ goto CleanUpDone
if exist %tempfile1% del %tempfile1%
:CleanUpDone
goto:EOF
--------------------------------------------
--------------------------------------------
:Usage
echo.
echo Usage: chkpath ^<path^>
echo checks if path element is included in path variable.
echo returns 1 if yes, 2 if no, 0 if not checked.
echo.
goto END
--------------------------------------------
:END
call :CleanUp
:ReallyEnd
endlocal & set errorlevel=%rc%
@REM set errorlevel=%rc%
@REM echo %errorlevel%
lpath.bat:
@echo.
@set curdrive=%~d0
@REM This form post-fixes a | at the end of each path element. Useful for debugging trailing spaces.
@REM @path | %curdrive%\cygwin\bin\sed.exe -e s/PATH=// -e 's/;/^|\n/g' -e 's/$/^|/g'
@REM This form shows bare path elements.
@REM @path | %curdrive%\cygwin\bin\sed.exe -e 's/PATH=//' -e 's/;/^\n/g'
@path | %curdrive%\utils\sed -e "s/PATH=//" | %curdrive%\utils\tr ; \n
@echo.