我的添加到系统路径脚本总是不可预知地弄乱路径
My add to system path script keeps messing with the path unpredictably
我制作了这个很好的批次,应该在 Windows 上添加系统 %PATH%
的给定路径:
@echo off
if exist %1\ (
setx PATH "%PATH%;%1"
) else (
echo %1 is NOT a folder
pause
)
exist %1\
是检查路径是否为文件夹的技巧。我什至为它制作了一个不错的上下文菜单项:
但问题是它会在系统路径中造成大量重复条目。您可能会注意到我省略了 /M
参数。那是故意的,我只想配置用户的系统路径。也就是说,我想我还需要能够专门获得该路径。此刻我认为它合并了系统和用户路径并做了一些额外的神秘混乱。
如果您的问题是如何清理路径,您可以将以下行 pathmgr.cmd /clean /user /y
添加到您的批处理中并下载 PathMgr batch script from here or here (gist)
>pathmgr /clean /user /?
CLEAN
Will clean up the PATH variable in the registry by removing
trailing and leading spaces, remove any enclosing double quotes,
remove duplicate paths and if /v specified will remove invalid paths.
The scope indicates wheteher user, system or both paths are cleaned.
By default will prompt if you want to make a permanaent
change to the registry. Note that any changes made to the path variable
not made permanent in the registry will be lost.
If you do not have administrator privileges you will not be able
to make changes to the system path.
SYNTAX: pathmgr /clean [scope] [modifiers]
[scope] /user|/system|/all
[modifiers] /v Will also delete any invalid paths
/p Display prompt to make registry change.
/y Do not ask, just make registry change (batch mode).
/n Do not make registry change (batch mode).
它还能做更多。
pathmgr Version 1.0.2
Tool to manage the PATH environment variable.
Provides tools to add to , delete from, clean up,
backup and restore the PATH environment variable
either on a session basis or make permanent changes
in the registry. To get help type "pathmgr /?".
Whenever pathmgr is run a temporary environment
variable pathmgr_PATH is created that holds the
current path of the pathmgr command file. The
/path switch may be used to add the path of pathmgr itself.
SYNTAX: pathmgr [/?|-?|] [action][modifier][scope][path]
[/?|-?] Display help, further help can be obtained on
a topic by including an action switch.
Example: pathmgr /? /List will provide help on list action.
[action] The management action to perform. Perermited values are:-
/list | /add | /del[ete] | /clean |/backup | /restore | /refresh | /path | /[env]ironment
[modifier] Some actions may have additional options.
/x: Expand environment variables.
/r: Reverse order.
/v: validate a path(s) existence.
/nv: no validation of path(s) existence.
/p: display all prompts
/y: hide prompts and choose yes
/n: hide prompts and choose no
/+: add current pathmgr to PATH
/-: delete current pathmgr from PATH
[scope] The scope within the registry to perform the action.
Permited values are:- /user | /system | /all.
The default scope is user as there are fewer
policy restrictions. System and All scopes may require
administrative privileges.
[path] Depending on context this will be either a folder or file path.
If the path is the only argument then the default action is /add.
Environment variables may be used in paths. The easiest way to do this
is to enclose the variable name within question marks '?' rather than
using the percent sign '', as an example ?systemroot?.
This practice has the advantage of working either from the commandline or
working within a batch. The alternative is to escape the variable as below.
If used on the command line use:- pathmgr /add ?systemroot?" or
pathmgr /add "^%systemroot^%". If used within a batch use
pathmgr /add "?systemroot?" or pathmgr /add "%%systemroot%%".
If these escaped paths are not used the path will be expanded prior to being
interpreted so if you really want the path to be C:\Windows without escaping
the path will be added as "c:\windows".
我制作了这个很好的批次,应该在 Windows 上添加系统 %PATH%
的给定路径:
@echo off
if exist %1\ (
setx PATH "%PATH%;%1"
) else (
echo %1 is NOT a folder
pause
)
exist %1\
是检查路径是否为文件夹的技巧。我什至为它制作了一个不错的上下文菜单项:
但问题是它会在系统路径中造成大量重复条目。您可能会注意到我省略了 /M
参数。那是故意的,我只想配置用户的系统路径。也就是说,我想我还需要能够专门获得该路径。此刻我认为它合并了系统和用户路径并做了一些额外的神秘混乱。
如果您的问题是如何清理路径,您可以将以下行 pathmgr.cmd /clean /user /y
添加到您的批处理中并下载 PathMgr batch script from here or here (gist)
>pathmgr /clean /user /?
CLEAN
Will clean up the PATH variable in the registry by removing
trailing and leading spaces, remove any enclosing double quotes,
remove duplicate paths and if /v specified will remove invalid paths.
The scope indicates wheteher user, system or both paths are cleaned.
By default will prompt if you want to make a permanaent
change to the registry. Note that any changes made to the path variable
not made permanent in the registry will be lost.
If you do not have administrator privileges you will not be able
to make changes to the system path.
SYNTAX: pathmgr /clean [scope] [modifiers]
[scope] /user|/system|/all
[modifiers] /v Will also delete any invalid paths
/p Display prompt to make registry change.
/y Do not ask, just make registry change (batch mode).
/n Do not make registry change (batch mode).
它还能做更多。
pathmgr Version 1.0.2
Tool to manage the PATH environment variable.
Provides tools to add to , delete from, clean up,
backup and restore the PATH environment variable
either on a session basis or make permanent changes
in the registry. To get help type "pathmgr /?".
Whenever pathmgr is run a temporary environment
variable pathmgr_PATH is created that holds the
current path of the pathmgr command file. The
/path switch may be used to add the path of pathmgr itself.
SYNTAX: pathmgr [/?|-?|] [action][modifier][scope][path]
[/?|-?] Display help, further help can be obtained on
a topic by including an action switch.
Example: pathmgr /? /List will provide help on list action.
[action] The management action to perform. Perermited values are:-
/list | /add | /del[ete] | /clean |/backup | /restore | /refresh | /path | /[env]ironment
[modifier] Some actions may have additional options.
/x: Expand environment variables.
/r: Reverse order.
/v: validate a path(s) existence.
/nv: no validation of path(s) existence.
/p: display all prompts
/y: hide prompts and choose yes
/n: hide prompts and choose no
/+: add current pathmgr to PATH
/-: delete current pathmgr from PATH
[scope] The scope within the registry to perform the action.
Permited values are:- /user | /system | /all.
The default scope is user as there are fewer
policy restrictions. System and All scopes may require
administrative privileges.
[path] Depending on context this will be either a folder or file path.
If the path is the only argument then the default action is /add.
Environment variables may be used in paths. The easiest way to do this
is to enclose the variable name within question marks '?' rather than
using the percent sign '', as an example ?systemroot?.
This practice has the advantage of working either from the commandline or
working within a batch. The alternative is to escape the variable as below.
If used on the command line use:- pathmgr /add ?systemroot?" or
pathmgr /add "^%systemroot^%". If used within a batch use
pathmgr /add "?systemroot?" or pathmgr /add "%%systemroot%%".
If these escaped paths are not used the path will be expanded prior to being
interpreted so if you really want the path to be C:\Windows without escaping
the path will be added as "c:\windows".