Subscribe
Notify of
guest

22 Comments
Oldest
Newest
Inline Feedbacks
View all comments
sferrell615

to remove an environment variable just enter
set =
e.g. set __COMPAT_LAYER=

Ciprian Adrian Rusen

The variable remains but, it has an empty value.

scififellow

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

remove from command line

SETX FOOBAR “” & REG delete HKCUEnvironment /F /V FOOBAR

Bryan

to delete and environment variable from the command line just set the variable to blank.

Gourav Dhol

Command to Delete User environment variable (Windows). Here “eclipse” is variable name

reg delete “HKCUEnvironment” /v eclipse /f

TVR

You can remove environment variables on the command line by typing:

SET var=

(not: SET var=””)

Lee

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

Jeremy Flowers

To remove an environment variable from the command line use SET envvarname=

Kyle_IT

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.

Anonymous

Good tip. Thanks!

Tom

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.

Ryg

To delete a user variable using command line, you can do it following way :
reg delete HKCUEnvironment /v FOOBAR /f

Stef

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

Is there a solution to delete 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

Steve S,

Delete env variable from the command line

SET Variable=

Vishnu

You can clear an environment variable on the command line by using:

set VARIABLE=

(Nothing after the equal sign)

Martin

this seems to do it:
set var=

RandomUser

You can delete environment variables from the command line via:

REG delete HKCUEnvironment /F /V VAR_NAME

Martha

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”

codeninja95

Can anyone please tell how to remove a path from path variable using command ?