Set Path from Command Line [Add to Path Windows]

By | April 7, 2022

Do you know, how to set the patch from the command line? The Windows command prompt allows users to run executable files by supplying the absolute path to the file. Regardless of whether it’s just an executable file name. Depending on which environment variable is associated with the executable, Windows will search across a list of folders. The following variables are part of the environment.

How to Add to Path Windows & Set Path from Command Line?

Set Path from Command Line [Add to Path Windows]
A. System path &
B. User path

In the system properties, you can check the values of these variables (run the sysdm.cpl from computer properties or Run). User-specific paths are initially empty in the environment variable. This variable can be used to specify paths to directories containing executables. Administrators can also modify the environment variable indicating the path to the system.

Using the command line, how do you set a path?

Set paths from the command line in Windows 7 and Windows 10 by using the “setx” command.

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

The following command can be run to add c:/dir1/dir2 to the path variable.

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

It is also possible to use “pathman.exe” from the Windows resource kit. In addition to removing a directory from the path variable, we are also able to use the command described above. The same applies to Windows 7 as well.

Add directory to system path to set environment variable Windows cmd:

Step-1: Open the command prompt from the administrator.
Step-2: Then you need to run the following command below.

pathman /as directoryPath

Environment variable for system path should be removed:

From an elevated command prompt, execute the following command.

pathman /rs directoryPath

An environment variable to set the user path:

Users do not need admin privileges to access user environment variables. Add the following command to the environment variable user path to add a directory.

pathman /au directoryPath

Here is the command you can run to remove the directories from the user path.

pathman /ru directoryPath

As a default, ‘2’ times is the maximum amount of time you can allow each user:

Having no double quotes around ‘path’ results in this error. For an example of setting the Firefox path, see the following.

C:\Users\>setx path %path%;"c:\Program Files (x86)\Mozilla Firefox\"
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.

When you move %path% inside double quotes it will look like this:

C:\Users\>setx path "%path%;c:\Program Files (x86)\Mozilla Firefox\"
SUCCESS: Specified value was saved.
C:\Users\>

Read: Stop Windows Update Service CMD

Leave a Reply

Your email address will not be published. Required fields are marked *