
Mein Versuch:
setx PATH "%PATH%;%~dp0"
Wie mache ich das, ohne dass alles im Systempfad im Benutzerpfad dupliziert wird?
Antwort1
Wie mache ich das, ohne dass der Systempfad im Benutzerpfad dupliziert wird?
Nutzen Sie die /m
Option.
setx /m PATH "%PATH%;%~dp0"
Anmerkungen:
/m
- Setzen Sie die Variable in der Systemumgebung HKLM. (Der Standard ist die lokale Umgebung HKCU)
setx
Verwendung
F:\test>setx /?
SetX has three ways of working:
Syntax 1:
SETX [/S system [/U [domain\]user [/P [password]]]] var value [/M]
Syntax 2:
SETX [/S system [/U [domain\]user [/P [password]]]] var /K regpath [/M]
Syntax 3:
SETX [/S system [/U [domain\]user [/P [password]]]]
/F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]
Description:
Creates or modifies environment variables in the user or system
environment. Can set variables based on arguments, regkeys or
file input.
Parameter List:
/S system Specifies the remote system to connect to.
/U [domain\]user Specifies the user context under which
the command should execute.
/P [password] Specifies the password for the given
user context. Prompts for input if omitted.
var Specifies the environment variable to set.
value Specifies a value to be assigned to the
environment variable.
/K regpath Specifies that the variable is set based
on information from a registry key.
Path should be specified in the format of
hive\key\...\value. For example,
HKEY_LOCAL_MACHINE\System\CurrentControlSet\
Control\TimeZoneInformation\StandardName.
/F file Specifies the filename of the text file
to use.
/A x,y Specifies absolute file coordinates
(line X, item Y) as parameters to search
within the file.
/R x,y string Specifies relative file coordinates with
respect to "string" as the search parameters.
/M Specifies that the variable should be set in
the system wide (HKEY_LOCAL_MACHINE)
environment. The default is to set the
variable under the HKEY_CURRENT_USER
environment.
/X Displays file contents with x,y coordinates.
/D delimiters Specifies additional delimiters such as ","
or "\". The built-in delimiters are space,
tab, carriage return, and linefeed. Any
ASCII character can be used as an additional
delimiter. The maximum number of delimiters,
including the built-in delimiters, is 15.
/? Displays this help message.
NOTE: 1) SETX writes variables to the master environment in the registry.
2) On a local system, variables created or modified by this tool
will be available in future command windows but not in the
current CMD.exe command window.
3) On a remote system, variables created or modified by this tool
will be available at the next logon session.
4) The valid Registry Key data types are REG_DWORD, REG_EXPAND_SZ,
REG_SZ, REG_MULTI_SZ.
5) Supported hives: HKEY_LOCAL_MACHINE (HKLM),
HKEY_CURRENT_USER (HKCU).
6) Delimiters are case sensitive.
7) REG_DWORD values are extracted from the registry in decimal
format.
Weitere Informationen
- Ein AZ-Index der Windows CMD-Befehlszeile- Ein hervorragendes Nachschlagewerk zu allem, was mit der Windows-Eingabeaufforderung zu tun hat.
- setx- Umgebungsvariablen dauerhaft festlegen. SETX kann zum Festlegen von Umgebungsvariablen für die Maschine (HKLM) oder den aktuell angemeldeten Benutzer (HKCU) verwendet werden.
Antwort2
[CMD, WMIC, HKLM, HKCU, SETX, PFAD, 2001]
das Problem ist wahrscheinlich über 20 Jahre alt:
-setx Pfad "%Pfad%;NeuerPfad"verunreinigt den Benutzerpfad mit dem Systempfad.
-setx Pfad "%Pfad%;NeuerPfad" /Mverunreinigt den Systempfad mit dem Benutzerpfad.
-die Verschmutzung:Video
Ich bin nicht sicher, ob es eine sichere native Lösung gibt, die NICHT-ANSI-Verzeichnisse berücksichtigt, die ausschließlich die Eingabeaufforderung verwenden.
das ist mein Versuch!
- unter Microsoft Windows [Version 10.0.19042.868]
0- Überprüfen Sie die Pfade
echo %Path%
reg query "HKCU\Environment" /v Path
reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v Path
reg EXPORT "HKCU\Environment" UserEnvironment.reg /y
reg EXPORT "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" SystemEnvironment.reg /y
wmic ENVIRONMENT where "username='<SYSTEM>' AND name='Path'" get variablevalue
wmic ENVIRONMENT where "username='%COMPUTERNAME%\\%USERNAME%' AND name='Path'" get variablevalue
Tipp: wmic ENVIRONMENT get *
[um mehr zu sehen]
die Info: Mit den obigen Befehlen wurde eine Registrierungssicherung durchgeführt. Die Dateien wurden im aktuellen Verzeichnis gespeichert.
1- Backup-Benutzerpfad unter%USERPATH%
- die Befehle setzen voraus:
- ungleich Null-Pfad;
- Funktionspfad;
- WennNulloderfunktionslosWegnurSchritt "2"
wmic ENVIRONMENT where "username='%COMPUTERNAME%\\%USERNAME%' AND name='Path'" get variablevalue | more +1 > %temp%\userpathvalue.txt
die Info: am Ende der Zeichenfolge befindet sich eine gewisse Verschmutzung*.
set /P USERPATH=<%temp%\userpathvalue.txt
- Hinzufügen, '/'
um Räume besser sehen zu können
set "USERPATH=%USERPATH%/"
- Entfernen Sie bis zu 15 Leerzeichen am Ende und entfernen Sie dann '/'
set "USERPATH=%USERPATH: /=/%"
set "USERPATH=%USERPATH: /=/%"
set "USERPATH=%USERPATH: /=/%"
set "USERPATH=%USERPATH: /=/%"
set "USERPATH=%USERPATH:/=%"
die Info: Die Anzahl der eingeführten Leerzeichen war in meinen Tests NICHT konsistent.
echo %USERPATH%[checking final string]
setx USERPATH "%USERPATH%"
* Beim Umgang mit unsichtbaren Zeichen ist es einfacher, sie zu identifizieren, indem man sie in Hexadezimalzahlen umwandelt. Gehen Sie dazu wie folgt vor:
wmic ENVIRONMENT where "username='%COMPUTERNAME%\\%USERNAME%' AND name='Path'" get variablevalue | more +1 > %tmp%\0 && set /P TEMPREADER=<%tmp%\0
echo %TEMPREADER% >%tmp%\1 && echo %TEMPREADER%/ && certutil -f -encodehex "%tmp%\1" "%tmp%\2" 11 | more +4 && type "%tmp%\2"
REM to open on notepad, type: certutil -f -encodehex "%tmp%\1" "%tmp%\2" 5 && cmd /C START "" /MAX notepad %tmp%\2
Tipp: verwenden Sie 4, 5, 10, 11 (dasselbe wie keine) in encodehex
2- setze¹²³ den Benutzerpfad als %USERPATH%
einzigen
setx PATH ^%USERPATH^%
Erledigt!
¹die Info: setx PATH "%USERPATH%"
setzt die VariableWertanstatt derwörtlich %USERPATH%
;
²die Info: Die Verwendung des Literals ist besser, da das Verhalten dynamisch statt statisch wird. Durch die Verwendung des Literals anstelle des Werts %USERPATH%
muss künftig also nur die Variable geändert werden. Durch die Verwendung des Werts (d. h. der in der Variablen vorhandenen Adressen) %PATH%
muss hingegen bei einer Änderung auch die Benutzervariable aktualisiert werden %USERPATH%
[was nicht wünschenswert ist].
³die Info: Die folgenden Methoden werden NICHT empfohlen! Sie funktionieren, aber es passieren leichter Fehler.
reg add "HKEY_CURRENT_USER\Environment" /v PATH /d ^%USERPATH^% /f
wmic ENVIRONMENT set name="PATH", variablevalue=^%USERPATH^%, username="%COMPUTERNAME%\\%USERNAME%"
3- vorerst nur verwenden%USERPATH%
setx USERPATH "%USERPATH%;ENTER-NEW-PATH-HERE"
Tipp: Schließen Sie alle Programme, insbesondere Terminals, bevor Sie fortfahren.
4- nochmal prüfen
echo %Path%
reg query "HKCU\Environment" /v Path
reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v Path
wmic ENVIRONMENT where "username='<SYSTEM>' AND name='path'" get variablevalue
wmic ENVIRONMENT where "username='%COMPUTERNAME%\\%USERNAME%' AND name='path'" get variablevalue
5- Sichtprüfung
rundll32 sysdm.cpl,EditEnvironmentVariables
die Info: Der Systempfad kann nur geändert werden, wenn der vorherige Befehl mit Administratorrechten ausgeführt wurde.
6-Kurz zusammengefasst:Tu es!/or don't!
REM the commands pre-suppose
REM - non-null path;
REM - functional path;
REM if null or unfunctionl path don't progress!
reg query "HKCU\Environment" /v Path
reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v Path
reg EXPORT "HKCU\Environment" UserEnvironment.reg /y
reg EXPORT "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" SystemEnvironment.reg /y
wmic ENVIRONMENT where "username='%COMPUTERNAME%\\%USERNAME%' AND name='Path'" get variablevalue | more +1 > %temp%\userpathvalue.txt
set /P USERPATH=<%temp%\userpathvalue.txt
set "USERPATH=%USERPATH%/"
set "USERPATH=%USERPATH: /=/%"
set "USERPATH=%USERPATH: /=/%"
set "USERPATH=%USERPATH: /=/%"
set "USERPATH=%USERPATH: /=/%"
set "USERPATH=%USERPATH:/=%"
echo %USERPATH%[checking final string] && echo %USERPATH% > %tmp%\0
certutil -f -encodehex "%tmp%\0" "%tmp%\1" 11 | more +4 && type "%tmp%\1"
setx USERPATH "%USERPATH%"
setx PATH ^%USERPATH^%
echo done!
REM setx USERPATH "%USERPATH%;ENTER-NEW-PATH-HERE"
REM please close all programs
Prost!
Antwort3
Es sieht so aus, als ob diese Seite das abdeckt, was Sie versuchen: PATH mit SETX oder PATHMAN oder etwas anderem hinzufügen? Oder fügen Sie Ihrer Frage vielleicht mehr Details hinzu, damit wir verstehen, was der Unterschied ist. Auf dieser Seite gibt es jedoch mehrere Lösungen für dasselbe oder ein ähnliches Problem wie das, nach dem Sie fragen.