有没有办法通过批处理文件(或powershell脚本)以编程方式将所有文件夹c:\Program Files
放入系统变量中PATH
?我依赖于命令行,真的想从命令行启动一个程序。
是的,我嫉妒 Linux shell。
将“C:\Program Files”作为参数传入此批处理文件:
@echo off
FOR /D %%G IN (%1\*) DO PATH "%%G";%path%
Doing this is very likely to break your computer, in the sense of invoking DLL Hell. As you invoke each executable, the OS will look through each directory in PATH
to find each DLL or even EXE referenced by that executable. It becomes highly likely that the OS will find the wrong ones as you add more directories to the PATH
.
So, a best practice is to avoid increasing the PATH
, and even to decrease it. Rather than implicit dependencies, make them explicit.
Instead, I recommend this approach:
bin
directory within your user home directorybin
directory to your user PATH
variablebin
directory for each application that you want to invoke from the command line (same name as the executable that you would type)SetLocal
, add the application's install directory (under %ProgramFiles%
) to the PATH
, then invoke the executable with the arguments from the command linePATH
, so that this script becomes the only way to invoke the executable