Set path from command line

by admin on July 16, 2013

Users can run an executable from windows command prompt either by giving the absolute path of the file or just by the executable file name. In the latter case, Windows searches for the executable in a list of folders which is configured in environment variables. These environment variables are as below.

1. System path
2. User path

The values of these variables can be checked in system properties( Run sysdm.cpl from Run or computer properties). Initially user specific path environment variable will be empty. Users can add paths of the directories having executables to this variable. Administrators can modify the system path environment variable also.

How to set path from command line?

In Vista, Windows 7 and Windows 8 we can set path from command line  using ‘setx’ command.

setx path "%path%;c:\directoryPath"

For example, to add c:\dir1\dir2 to the path variable, we can run the below command.

setx path "%path%;c:\dir1\dir2"

Alternative way is to use Windows resource kit tools ‘pathman.exe‘. Using this command we can even remove a directory from path variable. See download windows resource kit tools. This works for Windows 7 also.

Add directory to system path environment variable:

Open administrator command prompt
Run  the below command

pathman /as directoryPath

Remove path from system path environment variable:
Run the below command from elevated command prompt

pathman /rs directoryPath

Setting user path environment variable

For user environment varlables, admin privileges are not required. We can run the below command to add a directory to user path environment variable.

pathman /au directoryPath

To remove a directory from user path, you can run the below command.

pathman /ru directoryPath

{ 5 comments… read them below or add one }

Jo March 20, 2014 at 6:16 pm

Could a context entry be created for folders, perhaps an extended one… to add to path?

what about a multi-verb option, like copy as path?

Reply

Johny Why June 22, 2014 at 7:29 pm

hi, when i use setx at an administrator command line, it creates a USER variable, NOT the SYSTEM variable. What am i doing wrong? How do i change the SYSTEM path at command prompt? -thx

Reply

Sebastian Bärgård August 13, 2014 at 10:12 am

Johny Why
Answer: Try add the parameter /M

Reply

Nuno October 15, 2014 at 8:56 am

Hi, is there a way I can add an extra variable instead on deleting the currently one and put a new Variable on the Path.

I used the command setx /M “c:\Options”, and what it does is delete the current one and then puts that one there, all I want is to add the new variable to the current one. -thx

Reply

admin October 16, 2014 at 4:47 am

Nuno, pathman described above does exactly that. You can download the resource tools kit and get it.

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: