Reputation: 1412
For some reason I do not know, my echo %path%
has many duplicates of C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\
. As far as I know, long %path%
is bad because it slows the searching process. Is it safe to remove these duplicates?
I also noticed that there are two version of path variable: one for user variables and one for system variables. If I type echo %path%
in command prompt as normal user, it will show the concatenation of these two version (system version comes first). If I am to remove the duplicates, from which version should I remove?
(bold one is system version)
C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\MinGW\bin;C:\Python27;C:\Users\jie\AppData\Local\Microsoft\WindowsApps
Upvotes: 5
Views: 13511
Reputation: 23
I was still wondering why some processes have a duplicate part in the PATH
environment variable.
Some investigating, the problem occurs by processes started by explorer.exe. It does not occur for processes which were not initially a child process (or 'child process of child process') of explorer.exe.
I think, the user part
of the Windows PATH
environment variable is influencend by :
HKCU\Environment\Path
HKCU\Environment\1\Path
The process explorer.exe (which is runnng in the user context) loads both entries for the PATH
environment variable.
I deleted for the test HKCU\Environment\Path
when HKCU\Environment\1\Path
exists. The duplicate part of the PATH
environment variable no longer exists.
Deleting or modifying this registry key should be done very carefully. Probably you ran in other unexpected problems, because the Windows Path environment variable affects all new processes started by the current user.
Note
Microsoft encourages the usage of App Paths, because the more entries the path environment variable Path has, the more time Windows is spending for searching for specified files. With App Paths you can specify per executable name the folders where the executable should search.
More information: Microsoft Docs about App Paths.
Note: A process which is started by cmd.exe
or a .cmd or .bat does not look at the App Path
key, even though if you use start process.exe
the process.exe file will have a look at App Path\Process.exe\Path
.
Upvotes: 2
Reputation: 71
On Microsoft Technet (Scriptcenter) there used to be a small PowerShellScript which checks against duplicate paths: How to check for duplicate paths in PATH environment variable
(It's gone now, at the original location, but archive.org has a copy.)
Should be run in a PowerShell environment with admin rights. I do this after every uninstall of any software (Windows 10 x64).
Upvotes: 4
Reputation: 960
The paths you mention are system paths. They should stay in the PATH
variable in the system scope. You can remove the duplicates in the PATH
variable of the user scope, but you should reboot and check, if every application is still working (not because you deleted a duplicate, but to make sure you didn't delete something wrong by mistake). As usual, backup your PATH
variables somewhere, before you start.
Duplicates inside each scope can always be safely removed. The list is split at every semicolon and each resulting path in the list is searched. If there are duplicates, the same search simply executes twice in the worst case. In the best case, the system might recognize the duplicates (I'm not sure if this happens), but this would mean additional effort for recognizing. So your statement on slowing down is correct in any case.
The reason for you duplicates (if it wasn't you at least) might probably be some application you installed somewhen, which edited the PATH
variable improperly.
Upvotes: 1