Reload environment variables windows

how to refresh environment variables in windows

Overview –
Environment Variables in Windows

It seems that you’re learning to program and trying to refresh environment variables in Windows 11 without rebooting your computer and restarting your project and disrupting the workflow.

The Windows OS provides a way for system administrators to change the values of environment variables in the registry. A special section of the registry called “Environment” contains all user-defined environment variables. You can modify these values through the use of the “Regedit” application.

An environment variable is a named object that contains data used by one or more applications. The environment variables are stored in the registry, where they can be viewed and edited using standard tools.

By the end of this article, you’ll be able to refresh environment variables in Windows without rebooting your computer:

Using Chocolatey Package Manager (Recommended)

Using Command Prompt

What are Environment
Variables in Windows

Variables are used to store many sorts of data. System settings, inventory statuses, and other data can be stored in these variables. Environment Variables are a type of variable that contains environmental information about a computer. The environment variables in Windows can be used to make changes to the system without having to edit the registry.

The variables in the environment are used to define variables for a variety of purposes. Windows itself does not require them. You put up these variables, and they determine how Windows runs it. You can use them, for example, to identify your user or its location.

Environment Variables in Windows help you to assign values that will be used during the process of execution of any command on your computer. This will allow these commands to execute on a given set of values, altering their appearance.

1. Refresh
Environment Variables via Chocolatey Package Manager
(Recommended)

Step 1: Open the Command Prompt from the Start menu, copy and paste the following command to install chocolatey package manager on your PC:

@”%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe” -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command “[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://community.chocolatey.org/install.ps1’))” && SET “PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin”

command-to-install-chocolatey-to-refresh-environment-variables.webp

Command to install Chocolatey using CMD

Step 2: After installing the Chocolatey Package Manager, type the command “refreshenv” (without quotation marks) to refresh system variables.

command-to-refresh-environment-variables-using-chocolatey-tool.webp

Refresh environment variables using chocolatey

NOTE: After the installation of the chocolatey package manager, every time you type and execute the “refreshenv” command, the environment variables will be refreshed immediately, without the need to restart the computer.

2. Refresh
Environment Variables via Command Prompt (CMD)

Step 1: In the Start menu, search for Command Prompt and run it as an administrator.

command-prompt-icon-in-windows-11.webp

Command Prompt (CMD) Icon

Step 2: Type the command: “set PATH = c” (without quotation marks), press the enter key, and restart the Command Prompt.

set-path-c-command.webp

“set PATH = c” command

Step 3: Type the command: “echo %PATH%” (without quotation marks) and press the enter key to reset system variables using CMD.

echo-path-command-to-refresh-environment-variables.webp

“echo %Path%” command

NOTE: After installing the PostgreSQL (PgAdmin 4), I tried this way to update environment variables, and it worked nicely.

FAQs Related to
Environment Variables

What
is the difference between System variables and Environment
variables?

System environment variables are globally accessed by all users. The user Environment variables are specific only to the currently logged-in user and remain the default for the other users.

Where are the
system variables stored in the registry?

The actual location of system variables in the registry is: HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > Control > Session Manager > Environment.

Are environment
variables stored in memory?

Environment variables and command line parameters are kept together at the top of the process memory structure, above the layer.

Next
Steps

When you change the value of an environment variable in windows, the changes are not applied to your current windows session. You have to either log out and log in again or restart your device. But, in this article, we’ve covered how to reset environment variables in Windows 11 without rebooting the computer.

Variables can be accessed through DOS commands by typing “set”. They can also be accessed through other programs such as PowerShell and Command Prompt using the Control Panel applet or any other number of available applications for manipulating environment variables.

It’s important to know that the changes you make in the environment variables will be modified for other users of the system as well. They should not, however, be confused with Environment Variables in Windows.

Further, customize your computer’s configuration by referring to the related articles below.



Posted on

|



In

win10

description: Add a windows environment varibale without rebooting the computer

process to refresh environment variables without reboot windows

  • open cmd commend prompt window
  • input set PATH=C -> this will refresh the environment variables
  • close and restart cmd window
  • input echo %PATH% to test
  • Post author: killfun
  • Post link:
    http://search4fan.github.io/post/win10_new_system_variable_without_restart.html
  • Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.

🔄 Refresh Environment Variables in Windows Command Prompt Easily!

👋 Hey there, tech enthusiasts! Have you ever found yourself scratching your head when modifying or adding environment variables in Windows Command Prompt? 🤔 Don’t worry, we’ve got you covered! In this blog post, we will unravel the mystery behind efficiently refreshing environment variables without resorting to the tedious process of restarting CMD. 💡

The Dilemma: Restarting CMD for Refreshing Environment Variables

Let’s set the stage: you make changes to an environment variable, but alas, you realize that the changes won’t take effect until you restart the trusty old Command Prompt. 😫 This can be quite inconvenient, especially when dealing with complex setups or needing to quickly validate changes. Thankfully, Windows provides us with a handy solution that saves us from unnecessary frustration. 🙌

Introducing the Refresh Command: setx

Enter stage right, the setx command! This command allows you to refresh environment variables within seconds, no restart required. Isn’t that amazing? 😍 Here’s how it works:

  1. Open Command Prompt by typing «cmd» in the Windows search bar and clicking on the «Command Prompt» or «Command Prompt (Admin)» option.

  2. In the Command Prompt window, simply type the following command:

    setx VARIABLE_NAME "new_value"

    Replace VARIABLE_NAME with the name of the variable you want to modify or add, and "new_value" with the updated value you desire. For example, to modify the PATH variable, you could use:

    setx PATH "%PATH%;C:\new\path"

  3. Press Enter, and voilà! 🎉 The environment variable will be refreshed instantly, without the need to close and reopen your Command Prompt window.

By using the setx command, you can quickly update your environment variables on-the-fly, making troubleshooting and testing a breeze. 💨

Common Issues & Troubleshooting

If you encounter any issues while using the setx command, fear not! Here are two common problems and their solutions:

  1. The variable doesn’t immediately reflect the changes: In some cases, even after executing the setx command, the updated value might not appear immediately. To force the updates to take effect, close all open Command Prompt windows and relaunch them.

  2. Access denied while modifying environment variables: If you encounter an «Access Denied» error, try running Command Prompt as an administrator. Right-click on the Command Prompt icon and select the «Run as administrator» option.

If you still face issues after trying the above solutions, feel free to seek further assistance in our comments section!

Engage with Your Thoughts and Experiences!

We would love to hear about your experiences with refreshing environment variables using the setx command! Did it simplify your workflow? Do you have any alternative methods that work best for you? Share your thoughts and insights in the comments below. Let’s geek out together! 🤓

Don’t forget to share this blog post with your tech-savvy friends who might be battling the environment variable conundrum! The refreshment of their CMD awaits them. 😉🔁

Until next time, happy coding! 💻✨

RefrEnv — Refresh the Environment

Reload environment variables inside CMD, Bash, Powershell or Zsh every time you want environment changes to propagate, so you do not need to restart them after setting a new variable with setx or after installing a new app which adds new variables.

This is a better alternative to the Chocolatey refreshenv for cmd (and works for bash and zsh too (cygwin, Msys2 and GitBash)), which solves several problems in the chocolatey’s refreshenv, like:

  • The Chocolatey refreshenv act bad if the variable have some
    cmd meta-characters, see this test:

    add this to the path in HKCU\Environment: test & echo baaaaaaaaaad,
    and run the chocolatey refreshenv you will see that it prints
    baaaaaaaaaad which is very bad, and the new path is not added to
    your path variable.

    RefrEnv solves this and you can test it with any meta-character, even something so bad like:

    ; & % ' ( ) ~ + @ # $ { } [ ] , ` ! ^ | > < \ / " : ? * = . - _ & echo baaaad
    
  • refreshenv adds only system and user
    environment variables, but CMD adds volatile variables too
    (HKCU\Volatile Environment). RefrEnv will merge all the three and
    remove any duplicates.

  • refreshenv resets your PATH. RefrEnv appends the new path to the
    old path of the parent script which called RefrEnv. It is better
    than overwriting the old path, otherwise it will delete any newly
    added path by the parent script. (this can be changed by user choice
    to reset the path, see the description)

  • RefrEnv solve this problem described in a comment here by @Gene Mayevsky:

    refreshenv modifies env variables TEMP and TMP replacing them with values stored in HKCU\Environment. In my case I run the script to update env variables modified by Jenkins job on a slave that’s running under SYSTEM account, so TEMP and TMP get substituted by %USERPROFILE%\AppData\Local\Temp instead of C:\Windows\Temp. This breaks build because linker cannot open system profile’s Temp folder.

and more…

Usage:

git clone https://github.com/badrelmers/RefrEnv
cd RefrEnv

cmd

Works in all windows versions xp+

Powershell

Works in all Powershell versions V2+

bash:

Zsh:


Details:

Opciones for RefrEnv in CMD

NAME
   RefrEnv - Refresh the Environment for CMD

SYNOPSIS
   call refrenv.bat

DESCRIPTION
   By default with no arguments, this script will do a full 
   refresh (refresh all non critical variables*, and refresh the PATH).

   you can use the following variables to change the default behaviour:

   RefrEnv_ResetPath=yes       Reset the actual PATH inside CMD, then refresh
                               it with a new PATH. This will delete any PATH 
                               added by the script who called RefrEnv. It is 
                               equivalent to running a new CMD session.

   RefrEnv_debug=yes           Debug what this script do. The folder containing
                               the files used to set the variables will be
                               open, then see _NewEnv.sh, this is the file
                               which run inside your script to setup the new
                               variables, you can also revise the intermediate
                               .txt files.

Opciones for RefrEnv in Powershell

NAME
    RefrEnv - Refresh the Environment for Powershell/Pwsh

SYNOPSIS
    . .\refrenv.ps1
    
DESCRIPTION
    By default with no arguments, this script will do a full 
    refresh (refresh all non critical variables*, and refresh the PATH).

    you can use the following variables to change the default behaviour:
                                
    RefrEnv_ResetPath=yes       Reset the actual PATH inside Powershell, then refresh
                                it with a new PATH. This will delete any PATH 
                                added by the script who called RefrEnv. It is 
                                equivalent to running a new Powershell session.

Opciones for RefrEnv in Bash and Zsh

SYNOPSIS
    source refrenv.sh
    source refrenvz.sh

DESCRIPTION
    By default with no arguments, RefrEnv will do a full 
    refresh (refresh all non critical variables*, and refresh the PATH).

    you can use the following variables to change the default behaviour:
    
    RefrEnv_StrictRefresh=yes   Strict mode (secure refresh). this prevent refreshing a
                                variable if it is already defined in the actual bash/zsh session. 
                                The PATH will be refreshed.
                                
    RefrEnv_ResetPath=yes       Reset the actual PATH inside bash/zsh, then refresh it with a new PATH.
                                this will delete any PATH added by the script who called RefrEnv. 
                                it is equivalent to running a new bash/zsh session.

    RefrEnv_debug=yes           Debug what RefrEnv do. The folder containing the 
                                files used to set the variables will be open, then see 
                                _NewEnv.sh this is the file which run inside your script
                                to setup the new variables, you can also revise the 
                                intermediate .txt files.
                              
    RefrEnv_help=yes            Print the help.

        
    RefrEnv support the so called bash Strict Mode like: "set -eEu -o pipefail ; shopt -s inherit_errexit"
    you can use the Strict Mode safely in your parent script without worry.


Note

*critical variables: are the built-in variables which belong to cmd/bash/zsh or windows and should not be refreshed normally like:

Expand for details

- windows vars:
    ALLUSERSPROFILE APPDATA CommonProgramFiles CommonProgramFiles(x86)
    CommonProgramW6432 COMPUTERNAME ComSpec HOMEDRIVE HOMEPATH LOCALAPPDATA 
    LOGONSERVER NUMBER_OF_PROCESSORS OS PATHEXT PROCESSOR_ARCHITECTURE 
    PROCESSOR_ARCHITEW6432 PROCESSOR_IDENTIFIER PROCESSOR_LEVEL 
    PROCESSOR_REVISION ProgramData ProgramFiles ProgramFiles(x86) 
    ProgramW6432 PUBLIC SystemDrive SystemRoot TEMP TMP USERDOMAIN 
    USERDOMAIN_ROAMINGPROFILE USERNAME USERPROFILE windir SESSIONNAME
    
- bash vars:
    BASH BASHOPTS BASHPID BASH_ALIASES BASH_ARGC BASH_ARGV BASH_CMDS 
    BASH_COMMAND BASH_COMPLETION_VERSINFO BASH_LINENO BASH_REMATCH 
    BASH_SOURCE BASH_SUBSHELL BASH_VERSINFO BASH_VERSION COLUMNS 
    COMP_WORDBREAKS CYGWIN CYG_SYS_BASHRC DIRSTACK EUID EXECIGNORE 
    FUNCNAME GROUPS HISTCMD HISTCONTROL HISTFILE HISTFILESIZE HISTSIZE 
    HISTTIMEFORMAT HOME HOSTNAME HOSTTYPE IFS INFOPATH LANG LC_ALL 
    LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LINENO 
    LINES MACHTYPE MAILCHECK OLDPWD OPTERR OPTIND ORIGINAL_PATH OSTYPE PATH 
    PIPESTATUS POSIXLY_CORRECT PPID PRINTER PROFILEREAD PROMPT_COMMAND PS0 
    PS1 PS2 PS3 PS4 PWD RANDOM SECONDS SHELL SHELLOPTS SHLVL SSH_ASKPASS 
    TERM TERM_PROGRAM TERM_PROGRAM_VERSION TZ UID USER _backup_glob 
    CHILD_MAX BASH_COMPAT FUNCNEST COMP_TYPE COMP_KEY READLINE_LINE_BUFFER 
    READLINE_POINT PROMPT_DIRTRIM BASH_EXECUTION_STRING COPROC_PID COPROC 
    GLOBIGNORE HISTIGNORE SRANDOM READLINE_MARK EPOCHSECONDS EPOCHREALTIME 
    BASH_ARGV0 COMPREPLY COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS EMACS 
    FCEDIT FIGNORE HOSTFILE IGNOREEOF INPUTRC INSIDE_EMACS MAPFILE 
    READLINE_LINE REPLY TIMEFORMAT TMOUT TMPDIR histchars

RefrEnv was created to respond to this Stackoverflow thread: https://stackoverflow.com/questions/171588/is-there-a-command-to-refresh-environment-variables-from-the-command-prompt-in-w

Published 2019-01-23, 18:30

Do you know all those installation instructions that tell you to restart your Windows console after installing a tool that adds itself to your PATH so its binary can directly be called?

Well, today I learned there is a much easier way to achieve this:

refreshenv
>refreshenv
Refreshing environment variables from registry for cmd.exe. Please wait...Finished..

Thanks to meteor for telling me about this in its Chocolatey/choco output:

Environment Vars (like PATH) have changed. Close/reopen your shell to see the changes (or in powershell/cmd.exe just type `refreshenv`).

Diskussion zum Artikel

» Selbst kommentieren

Selbst kommentieren

Trackback-URI, Kommentarfeed.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Ограниченное управление доступом windows
  • Сетевое имя компьютера как найти windows 10
  • Не записывается звук при записи видео с экрана компьютера windows 10
  • Как выбрать при установке windows 10 pro
  • Обновление для системы безопасности windows xp embedded kb2686509