Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing to remove path from environment variable PATH

I'm trying to use a command line implementation to change the PATH environment variable to remove a path, so I don't have to manually remove it on a bunch of machines.

I have found this, which I can't seem to get it to work:

%Path:str1=str2%

str1 is the path and str2 is null, which I'm not sure how to set it to null on the command line.

If there is another way, I would be glad to give it a try.

like image 717
Bruce227 Avatar asked Jun 18 '10 19:06

Bruce227


People also ask

Can I delete PATH environment variable?

If you no longer want to use a particular environment variable, select it in the Environment Variables window. Then, press Delete. Windows does not ask for any confirmation of this action.

What will happen if we remove name from PATH variable?

What happens if you delete your path variable? Nothing much happens. A variable telling programs where to look for things is gone.

How do you separate paths in Environment Variables?

In the Environment Variables window (pictured below), highlight the Path variable in the System variables section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each directory path is separated with a semicolon, as shown below.


2 Answers

I have found this, which I can't seem to get it to work: %Path:str1=str2% str1 is the path and str2 is null, which I'm not sure how to set it to null on the command line.

Not sure why this didn't work for you, but here is an example that does work (at least on Windows XP).

set path=%path:c:\windows\system32;=%

This will remove "c:\windows\system32;" from the path variable. Make sure you have the ; on the end otherwise it may partially remove some other paths.

Remember that this will only affect the current instance of the command prompt. If you quit or work in a different command prompt, any changes you made to the environment variables will be lost.

like image 96
Grant Peters Avatar answered Sep 28 '22 02:09

Grant Peters


Using VBScript, you can get the path variable:

dim shell, env, path, path_entries
set shell = createobject("wscript.shell")
set env = shell.environment("system")
path = env("path")

Then split to get an array of the pieces:

path_entries = split(path, ";")

Set any entries to an empty string to remove them:

path_entries(3) = ""

Then reconstruct the path:

path = join(path_entries, ";") ' elements in path are delimited by ";"
env("path") = path
like image 45
Bryan Ash Avatar answered Sep 28 '22 02:09

Bryan Ash