What is the best/easiest way to add a directory to 'Path' when starting a CMD (MS-DOS) window? It used to be possible to do this with an AUTOEXEC.BAT file in XP.

kitti_1 commented: thanks u +0

Dani AI

Generated

Reverend Jim’s GUI steps are perfect for a permanent change. If you only want CMD sessions to pick up an extra folder without touching the system PATH, here are a few reliable options you can apply immediately.

  • One-off (current window only)

    Run this in a new CMD window. Putting your folder first gives it precedence.

    set "PATH=C:\Tools\bin;%PATH%"

    This affects only that window and its child processes. See the set command reference for scope details. Microsoft Learn

  • Shortcut that always prepends your folder

    Create a desktop shortcut whose Target is:

    %ComSpec% /k "set PATH=C:\Tools\bin;%PATH%"

    /k runs the command and leaves the shell open. Microsoft Learn

  • Auto-run on every CMD start (user only)

    This mimics the old AUTOEXEC.BAT behavior for cmd.exe. Note the doubled percent signs so expansion happens at launch, not when you write the value:

    reg add "HKCU\Software\Microsoft\Command Processor" ^
      /v AutoRun /t REG_EXPAND_SZ /d "set PATH=C:\Tools\bin;%%PATH%%" /f

    cmd.exe executes the AutoRun value on startup; use /d with cmd to bypass it if needed. Microsoft Learn

  • Permanent via command line (instead of the GUI)

    setx PATH "%PATH%;C:\Tools\bin"

    Open a new CMD to see the change. Be aware setx writes expanded values and truncates input over 1024 chars, so keep PATH tidy. Microsoft Learn

Tip: Verify which executable will run with your updated PATH:

where mytool.exe

If the first hit is not from your folder, move your folder earlier in PATH. Microsoft Learn

Recommended Answers

All 2 Replies

  1. Open an Explorer window
  2. Right click on This PC and select Properties from the pop-up menu
  3. In the Control Panel window click on Advanced system settings
  4. Click on Environment Variables

At this point you have to decide if you want the change to apply to just the current user, or for all users. You will click on Path in either the upper list (current user) of the lower list (all users).

  1. Click on the appropriate Edit... button.
  2. In the Edit environment variable window click New
  3. Enter the desired path info into the edit box
  4. Click OK
  5. Click OK
  6. Click OK
commented: OK. OK. OK. Don't take this wrong, that's how it's done. (Are your sure? OK!) +0

Thank you!
Chuck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.