Purpose:Remove variables from the environment or the registry


Format:UNSET [/= /D /E /Q /S /U /V /R file... (name ...)] name [name...]}]




nameOne or more variables to remove (wildcards accepted except for registry variables).
fileOne or more files from which to read variables to be removed.










See also: ESET and SET.


File Completion Syntax:


The default filename completion syntax is: [/r] * [1*] variables




UNSET removes one or more variables from the environment or from the Windows Registry.


You can also use regular expressions in the variable name.


UNSET can be used in a batch file, in conjunction with the SETLOCAL and ENDLOCAL commands, to clear the environment of variables that may cause problems for applications run from that batch file.


For more information on environment variables, see the SET command and the general discussion of the environment.


Note: You cannot use UNSET with GOSUB variables.


Use caution when removing environment variables, and especially when using UNSET *. Many programs will not work properly without certain environment variables; for example, TCC depends on PATH.


Registry Variables: Default, System, User, and Volatile registry variables can be manipulated with the UNSET command's /D, /S, /U and /V switches, respectively. To remove the variable from both the registry and from the local environment, use both the /E switch and the registry variable selection switch together. (You cannot use wildcards for the variable name.) For example, to remove the volatile variable myvar from both the registry and the local environment, use:


unset /v /e myvar


Use caution when directly removing registry variables as they may be essential to various Windows processes and applications.




To remove the environment variable CMDLINE:


unset cmdline


If you use the command UNSET *, all of the environment variables will be deleted:


unset *


You can delete all matching variables except for those specified by enclosing the exceptions in parentheses. For example, to remove all variables beginning with "v" except for var1 and var2:


unset (var1 var2) v*




/=Display the UNSET command dialog to help you set the command line options. The /= option can be anywhere on the line; additional options will set the appropriate fields in the command dialog.


/DDelete a default variable from the registry (HKU\.DEFAULT\Environment).


/EWhen used together with one of /D, /S, /U, or /V, unsets both the registry variable and the local environment variable.


/QPrevents UNSET from displaying any error messages.


/RRead environment variables to be UNSET from a file. This is much faster than using multiple UNSET commands in a batch file, and can be more selective than UNSET *. The file format may be the same as that used by the SET /R command (see SET for more details), or it could just be one variable per line, wildcards not processed.


UNSET /R will read from STDIN if no filename is present and input is redirected.


/SDelete a system variable from the registry  (HKLM\System\CurrentControlSet\Control\Session Manager\Environment).


/UDelete a user variable from the registry (HKCU\Environment).


/VDelete a volatile variable from the registry (HKCU\Volatile Environment)