If you can use PowerShell, you can define a machine environment variable with:
[Environment]::SetEnvironmentVariable(“MYVAR”, “MYVALUE”, [EnvironmentVariableTarget]::Machine)
and delete it with:
[Environment]::SetEnvironmentVariable(“MYVAR”, $null, [EnvironmentVariableTarget]::Machine)
Enviroment Variables are stored in the Registry keys:
HKEY_CURRENT_USEREnvironment (User)
Or
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession (System)
You can delete enviroment variables by deleting the keys themselves.
I want remove variable only temporarily for one command. How to do that? I don’t want remove permanently. I tried set envvar= && command using command chaining but it seems bug in windows, and set envvar= doesn’t clear variable as without chaining do.
To remove an environment variable using the command line simply set it to an empty value e.g. to remove for just this session you could execute “SET VariableName=” without the double quotes
22 Responses to “How to edit, clear, and delete environment variables in Windows”
Can anyone please tell how to remove a path from path variable using command ?
For system variable settings:
REG delete “HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment” /F /V “variable to delete”
If it is in the user environment:
REG delete “HKCUEnvironment” /F /V “variable to delete”
You can delete environment variables from the command line via:
REG delete HKCUEnvironment /F /V VAR_NAME
this seems to do it:
set var=
You can clear an environment variable on the command line by using:
set VARIABLE=
(Nothing after the equal sign)
Delete env variable from the command line
SET Variable=
Delete From Current Process
Obviously, everyone knows that you just do this to delete an environment variable from your current process:
set FOO=
Persistent Delete
There are two sets of environment variables, system-wide and user.
Delete User Environment Variable:
reg delete “HKCUEnvironment” /v FOO /f
Delete System-Wide Environment Variable:
REG delete “HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment” /F /V FOO
https://stackoverflow.com/questions/13222724/command-line-to-remove-an-environment-variable-from-the-os-level-configuration
Hello,
If you can use PowerShell, you can define a machine environment variable with:
[Environment]::SetEnvironmentVariable(“MYVAR”, “MYVALUE”, [EnvironmentVariableTarget]::Machine)
and delete it with:
[Environment]::SetEnvironmentVariable(“MYVAR”, $null, [EnvironmentVariableTarget]::Machine)
Rgds
Stef
To delete a user variable using command line, you can do it following way :
reg delete HKCUEnvironment /v FOOBAR /f
Enviroment Variables are stored in the Registry keys:
HKEY_CURRENT_USEREnvironment (User)
Or
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession (System)
You can delete enviroment variables by deleting the keys themselves.
Good tip. Thanks!
I want remove variable only temporarily for one command. How to do that? I don’t want remove permanently. I tried set envvar= && command using command chaining but it seems bug in windows, and set envvar= doesn’t clear variable as without chaining do.
To remove an environment variable from the command line use SET envvarname=
To remove an environment variable using the command line simply set it to an empty value e.g. to remove for just this session you could execute “SET VariableName=” without the double quotes
I’ve found this at StackOverflow: https://stackoverflow.com/questions/13222724/command-line-to-remove-an-environment-variable-from-the-os-level-configuration
You can remove environment variables on the command line by typing:
SET var=
(not: SET var=””)
Command to Delete User environment variable (Windows). Here “eclipse” is variable name
reg delete “HKCUEnvironment” /v eclipse /f
to delete and environment variable from the command line just set the variable to blank.
SETX FOOBAR “” & REG delete HKCUEnvironment /F /V FOOBAR
to remove an environment variable just enter=
set
e.g. set __COMPAT_LAYER=
The variable remains but, it has an empty value.
Works for me in cmdr prompt:
λ set david=hello
λ set | grep david
david=hello
C:downloadapache-tomcat-8.5.29_2
λ echo %david%
hello
λ set david=
λ set | grep david // no output here