706

I am trying to add C:\xampp\php to my system PATH environment variable in Windows.

I have already added it using the Environment Variables dialog box.

But when I type into my console:

C:\>path

it doesn't show the new C:\xampp\php directory:

PATH=D:\Program Files\Autodesk\Maya2008\bin;C:\Ruby192\bin;C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;C:\PROGRA~1\DISKEE~2\DISKEE~1\;c:\Program Files\Microsoft SQL
Server\90\Tools\binn\;C:\Program Files\QuickTime\QTSystem\;D:\Program Files\TortoiseSVN\bin
;D:\Program Files\Bazaar;C:\Program Files\Android\android-sdk\tools;D:\Program Files\
Microsoft Visual Studio\Common\Tools\WinNT;D:\Program Files\Microsoft Visual Studio\Common
\MSDev98\Bin;D:\Program Files\Microsoft Visual Studio\Common\Tools;D:\Program Files\
Microsoft Visual Studio\VC98\bin

I have two questions:

  1. Why did this happen? Is there something I did wrong?
  2. Also, how do I add directories to my PATH variable using the console (and programmatically, with a batch file)?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Netorica
  • 18,523
  • 17
  • 73
  • 108
  • 67
    This is on topic because it's a question about 'tools programmers commonly use'. If you develop on Windows and you've never needed to modify the PATH, I'm surprised. To satiate the desire for being related to programming, I've highlighted what the highest voted answer pointed out: You can do this programmatically through the console (or via a batch file). – George Stocker Mar 04 '14 at 17:31
  • 1
    thanks for the review @GeorgeStocker well yeah I did it programmatically and but I just haven't had an idea that I need to relogin after applying changes in the console session. (and I think its only in my case) but the highest voted answer generally answers the question – Netorica Mar 05 '14 at 01:00
  • 1
    @George - agreed, but as it stands, this question is written for Super User, and not Stack Overflow. Super User will provide help with web server configurations for personal use. Stack Overflow is for programming questions. – jww Sep 09 '14 at 13:04
  • 1
    Exit and open a new console... If you're using bash, that may require a system reboot before the changes persist, depending on how/what you are using,. – Tracker1 Nov 22 '16 at 20:47
  • Does this answer your question? [How to update PATH variable permanently from Windows command line?](https://stackoverflow.com/questions/8358265/how-to-update-path-variable-permanently-from-windows-command-line) – Dave Jarvis May 09 '21 at 19:28
  • How to access the 'Environment Variables window' from Explorer: _Right click on "This PC" > click on "Properties" > on the left panel of the window that pops up, click on "Advanced system settings" > click on the "advanced" tab > click on "environment variables" button at the bottom of the window._ ([via](/q/17240725#comment103016617_17242476)) Also might be neccessary to [refresh the registry](/q/4315265) afterwards. – cachius May 21 '22 at 22:51
  • I use https://www.rapidee.com/en/about – Chef Gladiator Oct 14 '22 at 05:23
  • Powershell options are discussed [here](/q/714877). – cachius Dec 07 '22 at 11:54

22 Answers22

1188

Option 1

After you change PATH with the GUI, close and reopen the console window.

This works because only programs started after the change will see the new PATH.

Option 2

This option only affects your current shell session, not the whole system. Execute this command in the command window you have open:

set PATH=%PATH%;C:\your\path\here\

This command appends C:\your\path\here\ to the current PATH. If your path includes spaces, you do not need to include quote marks.

Breaking it down:

  • set – A command that changes cmd's environment variables only for the current cmd session; other programs and the system are unaffected.
  • PATH= – Signifies that PATH is the environment variable to be temporarily changed.
  • %PATH%;C:\your\path\here\ – The %PATH% part expands to the current value of PATH, and ;C:\your\path\here\ is then concatenated to it. This becomes the new PATH.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JimR
  • 15,513
  • 2
  • 20
  • 26
  • 18
    @Ilya: I meant for you to open the console window after the path was changed in MyComputer->Properties->Advanced->Env Variables->Path. Some windows apps will propagate environment variable changes after they're started and some will not. WinXP cmd.exe does not. – JimR Jun 01 '12 at 09:17
  • 11
    if I exit the console and I rerun I have to reset the path. Any idea how to make this change permanent? – David 天宇 Wong Feb 05 '15 at 04:35
  • 3
    @David天宇Wong If you follow "My Computer" > "Properties" > "Advanced" > "Environment Variables" > "Path". and add the directory to the end of that string, it will stay. Just be sure to open console after making the change. – theB3RV Feb 13 '15 at 15:02
  • 1
    yup @theB3RV, it's just a long way to do something simple. It's weird that there is no persistant command that can be typed in the console – David 天宇 Wong Feb 13 '15 at 16:24
  • 15
    @David天宇Wong Just found "SETX is a way to make persistent changes, like the dialog." so the SETX command should do it – theB3RV Feb 13 '15 at 17:01
  • This is not persistent. As soon as you close your console window, your changes will be lost. – BrainSlugs83 Jul 03 '15 at 21:57
  • @BrainSlugs83 I'm guessing either I wasn't clear enough or you didn't see the first half of the answer. – JimR Aug 18 '15 at 21:29
  • What if path is already exists? It will be good to check for existance – Murali Murugesan Aug 01 '16 at 09:53
  • 1
    your answer seems to work only for the session, as soon as I exit and open a new command prompt, the path remains as it was at the start – J3STER Jan 31 '17 at 22:39
  • "Open the console window after you change the system path"... it's really helped out. thank you – NET3 Jan 13 '18 at 15:01
  • And how do you do this with a space in directory path. – basickarl Sep 12 '19 at 09:38
  • 2
    It would be nicer if you add a note that Option 2 is session-wide, not system-wide. – kaltu Mar 15 '20 at 02:27
273

WARNING: This solution may be destructive to your PATH, and the stability of your system. As a side effect, it will merge your user and system PATH, and truncate PATH to 1024 characters. The effect of this command is irreversible. Make a backup of PATH first. See the comments for more information.

Don't blindly copy-and-paste this. Use with caution.

You can permanently add a path to PATH with the setx command:

setx /M path "%path%;C:\your\path\here\"

Remove the /M flag if you want to set the user PATH instead of the system PATH.

Notes:

  • The setx command is only available in Windows 7 and later.
  • You should run this command from an elevated command prompt.

  • If you only want to change it for the current session, use set.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Nafscript
  • 5,155
  • 2
  • 17
  • 15
  • 8
    `SETX /M path "%path%;C:\Program Files (x86)\Git\bin\"` to set PATH value on machine level – Ilya Serbis May 29 '15 at 15:49
  • 14
    Why is this this not the accepted answer? I'd imagine most people would want to set their path permanently... – Peter Gordon Jun 29 '15 at 19:09
  • @pgmann The accepted answer also permanent. The only one that's not is the crazy upvoted one using `SET`. – BrainSlugs83 Jul 03 '15 at 22:02
  • 8
    See also [Overcoming the 1024 character limit with setx](http://superuser.com/q/387619) – DavidPostill Sep 25 '15 at 19:46
  • 17
    __WARNING__ : Because of the use of `%PATH%` variable, this command merge global env variables with users ones. Doesn't it ? This may creates unwanted side effects, especially with the /M switch – FF_Dev Oct 01 '15 at 09:51
  • 9
    __WARNING 2:__ The `%PATH%` variable may not be in sync with environment variables as it is loaded at the launch of the command prompt and never reloaded afterward (even when executing setx command). Also it could have been changed locally by previously executed scripts. – FF_Dev Oct 01 '15 at 09:58
  • Didn't work for me. At least when using "set" instead of "setx". I needed to add an = between the variable name and value i.e. set path="..." – overgroove Aug 23 '16 at 16:05
  • 1
    @overgroove That's because confusingly [`SET`](http://ss64.com/nt/set.html) and [`SETX`](http://ss64.com/nt/setx.html) have similar but different syntaxes. `SET PATH=...` vs `SETX PATH ...` – icc97 Dec 29 '16 at 09:40
  • 8
    **WARNING again** : Since this method merges/truncates data, be sure to **FIRST BACK-UP your %PATH% variable value**. I know, this might seem obvious, but I'm not used to such destructive and permanent behaviours with such a little command by our days (Especially since I've been playing with path for years). While it just screwed my PATH, I'd like to be able to restore it, and... I'm not :). This answer deserves a much more clear **WARNING**, about the fact that this method will, at the same time `add data`, `truncate data` and be `non-reversible`. – Balmipour Jun 27 '17 at 08:04
  • Finally, I can get a true Linux experience in Windows. Reminds me of https://devrant.com/rants/618148/rant – geneorama Dec 27 '18 at 20:53
  • While Balmipour's warning is correct, at least it truncated it for me in such a way that the GUI now works again. This command solved to problem for me that no matter how many entries I deleted from the path, it still could not save it because it was too long. – lucidbrot Apr 06 '21 at 07:24
  • tl;dr it's best to use GUI. From start menu search. – Polv Sep 15 '21 at 10:21
  • 1
    Please do not use this command under any circumstances, just use the GUI. My whole user path got overwritten after finding it on another website :( – Shidouuu Feb 05 '22 at 21:43
  • 2
    I just [**F***** UP my entire System PATH**](https://i.stack.imgur.com/1EAG2.png) using that command. Bad, very bad. – rustyx Feb 21 '22 at 14:35
  • If you deleted existing PATH by this command, you should try running `echo %PATH%` on your command prompt and run `setx /M path "%PATH%"` on command prompt. It worked for my case. – developer0hye Sep 09 '22 at 14:26
170

This only modifies the registry. An existing process won't use these values. A new process will do so if it is started after this change and doesn't inherit the old environment from its parent.

You didn't specify how you started the console session. The best way to ensure this is to exit the command shell and run it again. It should then inherit the updated PATH environment variable.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 9
    Hmm, no, it truly really only modifies the registry. Ought to be a bit obvious from doing this in a Control Panel dialog instead of, say, the command prompt with the PATH command. You can observe what it does easily with SysInternals' Process Monitor, should you care. Using PATH is *not* the same, any changes you make will be lost when the console closes. SETX is a way to make persistent changes, like the dialog. – Hans Passant Sep 12 '14 at 16:21
  • 3
    This is correct. You always have to restart your console session before it picks up new environment variables. – BrainSlugs83 Jul 03 '15 at 21:56
  • 1
    Would the console session update the variables if `WM_SETTINGCHANGE` message was sent from an apllication? http://stackoverflow.com/a/8358361 – John_West Jun 21 '16 at 16:28
  • It is theoretically possible, no practical CRT implementation I know of actually does this. Explorer does. – Hans Passant Jun 21 '16 at 16:35
  • 1
    Background information corroborating this: https://blogs.msdn.microsoft.com/oldnewthing/20150915-00/?p=91591 – Euro Micelli Dec 02 '16 at 03:43
  • Yes, it will, and I have implemented this feature a couple of times when I needed an environment variable to be both persisted in the Windows Registry and available for immediate use in the active session. – David A. Gray Jul 23 '18 at 07:35
90

You don't need any set or setx command. Simply open the terminal and type:

PATH

This shows the current value of PATH variable. Now you want to add directory to it? Simply type:

PATH %PATH%;C:\xampp\php

If for any reason you want to clear the PATH variable (no paths at all or delete all paths in it), type:

PATH ;

Update

Like Danial Wilson noted in comment below, it sets the path only in the current session. To set the path permanently, use setx but be aware, although that sets the path permanently, but not in the current session, so you have to start a new command line to see the changes. More information is here.

To check if an environmental variable exist or see its value, use the ECHO command:

echo %YOUR_ENV_VARIABLE%
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
zar
  • 11,361
  • 14
  • 96
  • 178
  • 1
    It worked :) how about that! 'PATH %PATH%;' I can remember that – Dustin Woodard Sep 20 '15 at 02:07
  • 16
    I think this only works for the instance of the cmd session, use setx to change it permanently – Daniel Wilson Oct 10 '15 at 13:34
  • 6
    **Don't** include quotes with this. For example call `PATH %PATH%;C:\Program Files\...` instead of `PATH "%PATH%;C:\Program Files\..."` – icc97 Mar 02 '17 at 17:34
  • 7
    Don't use setx! You risk truncation of your path variable, losing many other paths you spent time setting. Heed warnings above. – STWilson Mar 09 '17 at 20:39
  • 3
    @STWilson, too late to see your comment! – Code Learner Oct 12 '18 at 02:25
  • It looks like it worked but after i close the console and reopen, the path is not there and i can't find anything in the advanced system settings->environment->path –  Oct 20 '19 at 17:59
70

I would use PowerShell instead!

To add a directory to PATH using PowerShell, do the following:

$PATH = [Environment]::GetEnvironmentVariable("PATH")
$xampp_path = "C:\xampp\php"
[Environment]::SetEnvironmentVariable("PATH", "$PATH;$xampp_path")

To set the variable for all users, machine-wide, the last line should be like:

[Environment]::SetEnvironmentVariable("PATH", "$PATH;$xampp_path", "Machine")

In a PowerShell script, you might want to check for the presence of your C:\xampp\php before adding to PATH (in case it has been previously added). You can wrap it in an if conditional.

So putting it all together:

$PATH = [Environment]::GetEnvironmentVariable("PATH", "Machine")
$xampp_path = "C:\xampp\php"
if( $PATH -notlike "*"+$xampp_path+"*" ){
    [Environment]::SetEnvironmentVariable("PATH", "$PATH;$xampp_path", "Machine")
}

Better still, one could create a generic function. Just supply the directory you wish to add:

function AddTo-Path{
param(
    [string]$Dir
)

    if( !(Test-Path $Dir) ){
        Write-warning "Supplied directory was not found!"
        return
    }
    $PATH = [Environment]::GetEnvironmentVariable("PATH", "Machine")
    if( $PATH -notlike "*"+$Dir+"*" ){
        [Environment]::SetEnvironmentVariable("PATH", "$PATH;$Dir", "Machine")
    }
}

You could make things better by doing some polishing. For example, using Test-Path to confirm that your directory actually exists.

Mariano Desanze
  • 7,847
  • 7
  • 46
  • 67
Ifedi Okonkwo
  • 3,406
  • 4
  • 33
  • 45
  • 3
    for calling `SetEnvironmentVariable` with the `Machine` parameter you need to open the PowerShell with administrator rights – InsOp Sep 13 '16 at 21:34
  • it's bitterly disappointing that this "power" shell doesn't recognize %userprofile% nor $userprofile.. but then again, this is windows we're talking about – abbood Jul 27 '17 at 11:29
  • 4
    @abbood What you're looking for is `$env:userprofile`. – alexia Aug 12 '17 at 09:04
  • 4
    You should also specify either `user` or `machine` in the call of `GetEnvironmentVariable`. Otherwise, `$PATH` will contain the value of both the user and machine part of the registry which will unecessarily blow up the path variable when storing it again. – René Nyffenegger Feb 23 '19 at 07:23
58

Safer SETX

Nod to all the comments on the @Nafscript's initial SETX answer.

  • SETX by default will update your user path.
  • SETX ... /M will update your system path.
  • %PATH% contains the system path with the user path appended

Warnings

  1. Backup your PATH - SETX will truncate your junk longer than 1024 characters
  2. Don't call SETX %PATH%;xxx - adds the system path into the user path
  3. Don't call SETX %PATH%;xxx /M - adds the user path into the system path
  4. Excessive batch file use can cause blindness1

The ss64 SETX page has some very good examples. Importantly it points to where the registry keys are for SETX vs SETX /M

User Variables:

HKCU\Environment

System Variables:

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Usage instructions

Append to User PATH

append_user_path.cmd

@ECHO OFF
REM usage: append_user_path "path"
SET Key="HKCU\Environment"
FOR /F "usebackq tokens=2*" %%A IN (`REG QUERY %Key% /v PATH`) DO Set CurrPath=%%B
ECHO %CurrPath% > user_path_bak.txt
SETX PATH "%CurrPath%";%1

Append to System PATH

append_system_path.cmd. Must be run as administrator.

(It's basically the same except with a different Key and the SETX /M modifier.)

@ECHO OFF
REM usage: append_system_path "path"
SET Key="HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
FOR /F "usebackq tokens=2*" %%A IN (`REG QUERY %Key% /v PATH`) DO Set CurrPath=%%B
ECHO %CurrPath% > system_path_bak.txt
SETX PATH "%CurrPath%";%1 /M

Alternatives

Finally there's potentially an improved version called SETENV recommended by the ss64 SETX page that splits out setting the user or system environment variables.


Example

Here's a full example that works on Windows 7 to set the PATH environment variable system wide. The example detects if the software has already been added to the PATH before attempting to change the value. There are a number of minor technical differences from the examples given above:

@echo off
set OWNPATH=%~dp0
set PLATFORM=mswin

if defined ProgramFiles(x86)                        set PLATFORM=win64
if "%PROCESSOR_ARCHITECTURE%"=="AMD64"              set PLATFORM=win64
if exist "%OWNPATH%tex\texmf-mswin\bin\context.exe" set PLATFORM=mswin
if exist "%OWNPATH%tex\texmf-win64\bin\context.exe" set PLATFORM=win64

rem Check if the PATH was updated previously
echo %PATH% | findstr "texmf-%PLATFORM%" > nul

rem Only update the PATH if not previously updated
if ERRORLEVEL 1 (
  set Key="HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
  for /F "USEBACKQ tokens=2*" %%A in (`reg query %%Key%% /v PATH`) do (
    if not "%%~B" == "" (
      rem Preserve the existing PATH
      echo %%B > currpath.txt

      rem Update the current session
      set PATH=%PATH%;%OWNPATH%tex\texmf-%PLATFORM%\bin
      
      rem Persist the PATH environment variable
      setx PATH "%%B;%OWNPATH%tex\texmf-%PLATFORM%\bin" /M
    )
  )
)

1. Not strictly true

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
icc97
  • 11,395
  • 8
  • 76
  • 90
27

Handy if you are already in the directory you want to add to PATH:

set PATH=%PATH%;%CD%

It works with the standard Windows cmd, but not in PowerShell.

For PowerShell, the %CD% equivalent is [System.Environment]::CurrentDirectory.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nclord
  • 1,287
  • 1
  • 16
  • 17
7

Aside from all the answers, if you want a nice GUI tool to edit your Windows environment variables you can use Rapid Environment Editor.

Try it! It's safe to use and is awesome!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Netorica
  • 18,523
  • 17
  • 73
  • 108
  • 3
    Windows 10 has significantly improved the Path Environment variable editor now. Only took them 20 years to get round to it. – icc97 Dec 29 '16 at 08:10
5
  • Command line changes will not be permanent and will be lost when the console closes.
  • The path works like first comes first served.
  • You may want to override other already included executables. For instance, if you already have another version on your path and you want to add different version without making a permanent change on path, you should put the directory at the beginning of the command.

To override already included executables;

set PATH=C:\xampp\php;%PATH%;

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hevi
  • 2,432
  • 1
  • 32
  • 51
5

Use pathed from gtools.

It does things in an intuitive way. For example:

pathed /REMOVE "c:\my\folder"
pathed /APPEND "c:\my\folder"

It shows results without the need to spawn a new cmd!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
womd
  • 3,077
  • 26
  • 20
  • 2
    gtools can be easily installed using e.g. [scoop](https://scoop.sh/) with a oneliner: `scoop install gtools` in case this is useful for anyone else – user2305193 Jan 11 '21 at 12:17
3

Checking the above suggestions on Windows 10 LTSB, and with a glimpse on the "help" outlines (that can be viewed when typing 'command /?' on the cmd), brought me to the conclusion that the PATH command changes the system environment variable Path values only for the current session, but after reboot all the values reset to their default- just as they were prior to using the PATH command.

On the other hand using the SETX command with administrative privileges is way more powerful. It changes those values for good (or at least until the next time this command is used or until next time those values are manually GUI manipulated... ).

The best SETX syntax usage that worked for me:

SETX PATH "%PATH%;C:\path\to\where\the\command\resides"

where any equal sign '=' should be avoided, and don't you worry about spaces! There isn't any need to insert any more quotation marks for a path that contains spaces inside it - the split sign ';' does the job.

The PATH keyword that follows the SETX defines which set of values should be changed among the System Environment Variables possible values, and the %PATH% (the word PATH surrounded by the percent sign) inside the quotation marks, tells the OS to leave the existing PATH values as they are and add the following path (the one that follows the split sign ';') to the existing values.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

Regarding point 2, I'm using a simple batch file that is populating PATH or other environment variables for me. Therefore, there isn’t any pollution of environment variables by default. This batch file is accessible from everywhere so I can type:

mybatchfile

Output:

-- Here all environment variables are available

And:

php file.php
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Grzegorz Gajos
  • 2,253
  • 19
  • 26
  • 1
    This is an important difference between *nix-es and Windows. The batch runs in the same shell, and changes to the environment stay after it exits (at session scope). However, this cuts both ways: a batch file can obliterate your environment. (BTW, on *nix-es you'd just have to `source` such a file, like `. mybatchfile`). – Tomasz Gandor Sep 13 '16 at 22:41
  • Hi @grzegorz-gajos, I was looking for exactly that, your link for more details gives 404. Any alternatives? – user6552940 Dec 23 '18 at 02:45
  • Sorry, the content from the link is no longer available. I removed. – Grzegorz Gajos Jan 02 '19 at 07:38
2

Use these commands in the Bash shell on Windows to append a new location to the PATH variable

PATH=$PATH:/path/to/mydir

Or prepend this location

PATH=/path/to/mydir:$PATH

In your case, for instance, do

PATH=$PATH:C:\xampp\php

You can echo $PATH to see the PATH variable in the shell.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kiriloff
  • 25,609
  • 37
  • 148
  • 229
  • 1
    What is the *"the Bash shell on Windows"*? [Git Bash](https://superuser.com/questions/1053633/what-is-git-bash-for-windows-anyway)? [Cygwin](https://en.wikipedia.org/wiki/Cygwin)? [WSL](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)? Something else? – Peter Mortensen Jan 25 '23 at 18:54
  • Executing `PATH=$PATH:/path/to/mydir` at a Windows cmd prompt just wipes out your path and requires you to login again to fix. Downvoted. – bikeman868 Jun 05 '23 at 23:11
1

In a command prompt you tell Cmd to use Windows Explorer's command line by prefacing it with start.

So start Yourbatchname.

Note you have to register as if its name is batchfile.exe.

Programs and documents can be added to the registry so typing their name without their path in the Start - Run dialog box or shortcut enables Windows to find them.

This is a generic reg file. Copy the lines below to a new Text Document and save it as anyname.reg. Edit it with your programs or documents.

In paths, use \\ to separate folder names in key paths as regedit uses a single \ to separate its key names. All reg files start with REGEDIT4. A semicolon turns a line into a comment. The @ symbol means to assign the value to the key rather than a named value.

The file doesn't have to exist. This can be used to set Word.exe to open Winword.exe.

Typing start batchfile will start iexplore.exe.

REGEDIT4
;The bolded name below is the name of the document or program, <filename>.<file extension>

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\Batchfile.exe]

; The @ means the path to the file is assigned to the default value for the key.
; The whole path in enclosed in a quotation mark ".

@="\"C:\\Program Files\\Internet Explorer\\iexplore.exe\""

; Optional Parameters. The semicolon means don't process the line. Remove it if you want to put it in the registry

; Informs the shell that the program accepts URLs.

;"useURL"="1"

; Sets the path that a program will use as its' default directory. This is commented out.

;"Path"="C:\\Program Files\\Microsoft Office\\Office\\"

You've already been told about path in another answer. Also see doskey /? for cmd macros (they only work when typing).

You can run startup commands for CMD. From Windows Resource Kit Technical Reference

AutoRun

HKCU\Software\Microsoft\Command Processor

Data type Range Default value
REG_SZ  list of commands  There is no default value for this entry.

Description

Contains commands which are executed each time you start Cmd.exe.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

A better alternative to Control Panel is to use this freeware program from SourceForge called Pathenator.

However, it only works for a system that has .NET 4.0 or greater such as Windows 7, Windows 8, or Windows 10.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bimo
  • 5,987
  • 2
  • 39
  • 61
1

If you run the command cmd, it will update all system variables for that command window.

Pranav Sharma
  • 232
  • 2
  • 8
  • 1
    In a sense. What happens is that you start a new session within the current session. Leaving will require you call `exit` twice, first to close the new and then to close the first session (with the old environment). – Farway Jul 24 '19 at 13:49
1

As trivial as it may be, I had to restart Windows when faced with this problem.

I am running Windows 7 x64. I did a manual update to the system PATH variable. This worked okay if I ran cmd.exe from the stat menu. But if I type "cmd" in the Windows Explorer address bar, it seems to load the PATH from elsewhere, which doesn't have my manual changes.

(To avoid doubt - yes, I did close and rerun cmd a couple of times before I restarted and it didn't help.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
svinec
  • 679
  • 8
  • 9
  • Is there an explanation? – Peter Mortensen Jun 27 '20 at 16:51
  • I don't know the technicality behind this, but Windows is just notorious with this, always restart first and only after that continue troubleshooting... – svinec Jun 28 '20 at 17:29
  • 1
    The reason is, that windows explorer didn't process the `WM_SETTINGCHANGE` message. And CMD that it spawns have no idea that it was changed. You don't need to restart OS, just restart `explorer.exe`. – ScienceDiscoverer Jul 24 '22 at 18:08
1

The below solution worked perfectly.

Try the below command in your Windows terminal.

setx PATH "C:\myfolder;%PATH%"

SUCCESS: Specified value was saved.

You can refer to more on here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

How to open the Environment Variables window from cmd.exe/Run... dialog

  • SystemPropertiesAdvanced and click "Environment Variables", no UAC
  • rundll32 sysdm.cpl,EditEnvironmentVariables direct, might trigger UAC

Via Can the environment variables tool in Windows be launched directly? on Server Fault.

How to open the Environment Variables window from Explorer

  1. right-click on "This PC"
  2. Click on "Properties"
  3. On the left panel of the window that pops up, click on "Advanced System Settings"
  4. Click on the "Advanced" tab
  5. Click on "Environment Variables" button at the bottom of the window

You can also search for Variables in the Start menu search.

Reference images how the Environment Variables window looks like:

Windows 10

Environment Variables window on Windows 10
via

Windows 7

Environment Variables window on Windows 7
via

Windows XP

Environment Variables window on Windows
via

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
cachius
  • 1,743
  • 1
  • 8
  • 21
0
  1. I have installed PHP that time. I extracted php-7***.zip into C:\php</i>

  2. Back up my current PATH environment variable: run cmd, and execute command: path >C:\path-backup.txt

  3. Get my current path value into C:\path.txt file (the same way)

  4. Modify path.txt (sure, my path length is more than 1024 characters, and Windows is running few years)

  • I have removed duplicates paths in there, like 'C:\Windows; or C:\Windows\System32; or C:\Windows\System32\Wbem; - I've got twice.
  • Remove uninstalled programs paths as well. Example: C:\Program Files\NonExistSoftware;
  • This way, my path string length < 1024 :)))
  • at the end of the path string, add ;C:\php\
  • Copy path value only into buffer with framed double quotes! Example: "C:\Windows;****;C:\php" No PATH= should be there!!!
  1. Open Windows PowerShell as Administrator (e.g., Win + X).

  2. Run command:

    setx path "Here you should insert string from buffer (new path value)"

  3. Rerun your terminal (I use "Far Manager") and check:

    php -v

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Serb
  • 21
  • 4
0

In my case it was just that I copied the path from the properties dialog box in Windows and it contained a blank character or something else in the text so it was not recognized. I pasted the path text in a plain text file and removed everything to the sides and my variable was recognized.

S. Feunmajer
  • 315
  • 2
  • 6
-2

On Windows 10, I was able to search for set path environment variable and got these instructions:

  1. From the desktop, right-click the very bottom-left corner of the screen to get the Power User Task Menu.
  2. From the Power User Task Menu, click System.
  3. In the Settings window, scroll down to the Related settings section and click the System info link.
  4. In the System window, click the Advanced system settings link in the left navigation panel.
  5. In the System Properties window, click the Advanced tab, then click the Environment Variables button near the bottom of that tab.
  6. 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 different directory is separated with a semicolon, as shown below:

C:\Program Files;C:\Winnt;C:\Winnt\System32

The first time I searched for it, it immediately popped up the System Properties Window. After that, I found the above instructions.

Janin
  • 292
  • 1
  • 2
  • 7