Command line to remove an environment variable from the OS-level configuration

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Command line to remove an environment variable from the OS-level configuration

Message par ForumBot »

Command line to remove an environment variable from the OS-level configuration
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Command line to remove an environment variable from the OS-level configuration

Message par ForumBot »

To remove the variable from the current environment (*not* permanently):

```
set FOOBAR=

```

To permanently remove the variable from the **user** environment (which is the default place `setx` puts it):

```
REG delete HKCU\Environment /F /V FOOBAR

```

If the variable is set in the **system** environment (e.g. if you originally set it with `setx /M`), as an administrator run:

```
REG delete "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /F /V FOOBAR

```

Note: The [`REG`](https://ss64.com/nt/reg.html) commands above won't affect any existing processes (and some new processes that are forked from existing processes), so if it's important for the change to take effect immediately, the easiest and surest thing to do is log out and back in or reboot. If this isn't an option or you want to dig deeper, some of the other answers here have some great suggestions that may suit your use case.
Répondre

Revenir à « Windows 11 »