adding PATH with SETX or PATHMAN or something else?

12

6

I am trying to add a PATH from command line, as with SETX %PATH%... it always expands the PATH, which I don't want.

PATHMAN is exactly for this purpose, but it doesn't work for me on Windows 7. It freezes most of the times, and it doesn't check for duplicated.

There must be a tool for managing PATH variables in the proper way. SETX would be perfect, but maybe not with the %PATH% syntax.

hyperknot

Posted 2011-04-08T12:54:59.793

Reputation: 734

Answers

13

See the article Edit the PATH environment variable in Windows without pain.

It recommends using pathed :

For example, say that you have your Sysinternal tools in C:\Bin\Sysinternals and you want to add them to the PATH. Simply do:

pathed /append C:\Bin\Sysinternals /machine

If you want to add them to the user PATH system instead, then do:

pathed /append C:\Bin\Sysinternals /user

harrymc

Posted 2011-04-08T12:54:59.793

Reputation: 306 093

This is exactly what I was looking for! From the article, I have tried the other 3 solutions already without happiness. It seems this is the one I was looking for. Works perfectly! BTW, it has nothing to do with Sysinternals. – hyperknot – 2011-04-08T16:27:01.760

This is supposed to work but it has an essential bug, if you try to ADD/APPEND something to the the user path and user path is not defined the utility will fail to add the path. – sorin – 2011-09-21T14:22:11.500

1I just gave this app a try; it was frustrating that it didn't seem to work. I realized that I have to run it while logged in as an Administrator, OR run it in a command shell that was started with "Run as Administrator". Also, you may need to categorically use "/machine" if you want affect the machine level path. Good luck! And thanks to @harrymc for the tip; +1 from me! – Dan H – 2012-09-12T13:17:31.533

FWIW, there is another "pathed" utility published on code.google.com which seems to do pretty much the same with a slightly different syntax.

– syneticon-dj – 2014-04-03T11:19:40.657

4

(I know that you've already answered this question, but)

The problem with your usage of setx is that you are not quoting the string that you want to be set. Because the ; character is a command delimiter (you can string commands to be run in-succession with it), it thinks that you are setting path and then running another command.

What you should do is this:

setx /M path "C:\perl\bin;%path%"

This prepends my %path% variable with C:\perl\bin, because I want it to come before anything else that may be installed. The /M means that I mean the System EnvVar, not the user's.

gWaldo

Posted 2011-04-08T12:54:59.793

Reputation: 318

2It will truncate paths longer than 1024 – wayofthefuture – 2017-09-14T14:15:44.097

1

There are three which I know methods out of which one is permanent(when adding in environment variables) and other 2 r temp.. just for setting path and thus the path set by them is destroyed after cmd is terminated(closed). Starting with methods:-

  1. Temporary method 1:-

    setx PATH "%PATH%;c:\path name;"

  2. Temporary method 2:-

    set PATH=c:\path name;%PATH%

  3. Permanent Method:-

    pathed /append c:\path name /machine (for all users) pathed /append c:\path name /user (for current user)

Chaitanya Bhardwaj

Posted 2011-04-08T12:54:59.793

Reputation: 11

-1

Under Windows 10 x64 1909 (and probably earlier builds) use the Start Menu Search feature with "set variables" to find and run either of the following returned results to access the MS revised graphical editor by selecting [Environment Variables] button: - Edit the system environmental variables - Edit environmental variables for your account

The editor is also accessible via the [Environment Variables] button on the old System Properties dialog.

Barney Blue

Posted 2011-04-08T12:54:59.793

Reputation: 1