The variable Path
has character length limitations...
1) Because it is a Bat
that does not delete/remove any file or folder, you can add this Bat
in the folder of Windows
, thus taking advantage that this folder already has its complete path saved in the variable Path
, and yet, no additional action/configuration will be required for this to work, also without bumping into any limitation problem, due to errors reported on the variable Path
, (commented/lynched on item 2).
-
For this, it is necessary to execute the cmd.exe
as administrador:
The command to create the Bat
to that end, it would be:
echo/@echo off ^& taskkill /f /im "%~1" %2>"%windir%\tk.cmd"
After this done, just type in any drive:\pasta o comando
:
tk chrome.exe /t
tk firefox.exe
tk qualquer.exe
Note: 1) The parameter/argument %2
may or may not be used, but in itself, this informs the taskkill.exe
to finalize also some child process created/started by the executable to be finished. There are times it is useful when some plugin "Buga/latch" when finishing the browsed (example).
Note: 2) Many software developers/vendors/drives/components, such as Nvidia, also use the folder Windows to keep some Bats, and run them when necessary without adding/adding more folders/paths to the environment variable `Path.
2) When using a specific folder to maintain and run one or more bats
, it will be necessary to add the path of that folder in the global variable Path
.
Obs.: It is possible to use the instructions present in the operator’s response @Guilherme Nascimento
, or use the command SetX
to configure this value, so that it will be possible to view in the execution/output, any occurrence of error/warning: setx /M Path "%Path%;c:\Pasta_BATs"
-
For this, it is also necessary to execute the cmd.exe
as administrador:
Consider
Just to make it possible aviso/erro
in executing the command, as there are reported problems by users, due to a limit on character length of the values assigned to the variable Path
.
- Posts commenting/addressing the limiting:
StackOverFlow
Environment Variable is Too large on Windows 10 # 38632 Views
SuperUser
Why does Windows have a limit on Environment variables at all? # 13215 Views
YouTube
Solved - Environment or User PATH Variable length limitation # 643 Hits
Intel
Limitation to the length of the System PATH variable # No informs Visits
-
When executing the command SetX
, I received the warning:
-
"data is truncated to 1024 characters when saved."
The character length in my variable Path
was 1412 characters before adding/editing the variable, and the number of folders present in it were 32.
After adding the folder c:\Pasta_BATs
, the character count dropped to 1185, and the number of folders went to 28?.
So we have a divergence of information from the graphical interface and on the command line, which one is most accurate?
The values of the variable Path
in the console/command line environment, these are (full) folder paths, divided by the delimiter ;
.
The values of the variable Path
on the interface of Advanced System Settings, are displayed in a path and folder listing, one item per line, no delimiter.
Completion
-
Lost some folders after adding value c:\Pasta_BATs
in the variable Path
, so I considered using the Windows for the Bats
my Bats, it is simpler, as also do some component manufacturers/drivers/softers/etc..
-
For those who prefer to use this variable, adding more paths to the variable Path
, recommend watching the link video Youtube, remembering that there is comment in the passage citing not being possible/achievable in the Windows 10 the steps shown in the post, given the fact that, the display in the graphical interface is sectioned in a listing, is not a display of the complete content with a delimiter, only individual value listing.
Doesn’t it pay to just create a link in your path, or even a bat to stay permanent? something like Tk.bat or Tk.cmd with @echo off n taskkill /f /im %1 content - I find it more practical than using a Doskey and having to make startup script to persist
– Bacco
you can create a batch file that takes its name as a parameter and execute the command
– Ricardo Pontual