This command-line tool offers a batch method for setting environmental
variables in the user or system environment and requires no programming or
scripting. In addition to taking an environmental variable and its associated
value from the command line, it can also get the values of registrykeys and
write them to text files.
SetX provides the only command-line or programmatic way to directly set
system environment values for Microsoft Windows 2000. System environment
variables are manually configureable through Control Panels or through a
registry editor (Regedit or Regedt32). The SET command, which is internal
to the command interpreter (Cmd.exe), sets only user environment variables
for the current console window.
You can use SetX to set values for user and system environment variables
from one of three sources: Command Line Mode, Registry Mode, or File Mode.
To display command-line options and details about syntax for all three modes, type:
setx /? or setx (without parameters)
For additional information and examples for all three modes, type:
setx -i
top
Command-Line Mode Syntax
setx variable value [-m]
Where:
- variable
- is the name of the environmental variable to be set.
- value
- is the value to which the environmental variable will be set.
- -m
- specifies that the value being set is in the system environment. The default is the user environment.
top
Registry Mode Syntax
setx variable -k hive\key\...\value [-m]
Where:
- variable
- is the name of the environmental variable to be set.
- -k
- specifies that the variable is set based on information from a registry key.
- hive\key\...\value
- is the registry path to the value for the environmental variable. For example: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName
- -m
- specifies that the value being set is in the system environment. The default is the user environment.
top
File Mode Syntax
setx variable -f filename {-a x,y | -r x,y "string"} [-d d] [-x] [-m]
Where:
- -f filename
- specifies the name of the file to use.
- -a x,y
- specifies absolute coordinates and offset as search parameters.
- -r x,y "string"
- specifies relative coordinates and offset from string as search parameters.
- -d d
- specifies additional delimiters (d) such as "," or "\".
The 4 built-in delimiters are space, tab, carriage return and linefeed. Any ASCII character can be used as an additional delimiter. The maximum number of delimiters, including the 4 built-in ones, is 15.
- -x
- displays file coordinates. Switches -a, -r, and -d are ignored.
- -m
- specifies that the value being set is in the system environment. The default is the user environment.
top
Known Limitations
The following list contains known limitations for setx:
- SetX writes variables to the master environment in the registry. Variables set with SetX variables are available only in future command windows, not in the current command window. This is a limitation of Windows 2000.
- When gaining access to REG_MULTI_SZ values in the registry, only the first item is extracted and used.
- The only supported hives are HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE.
- Values added to the user or system environments cannot be removed with SetX. A corresponding value can be removed from the local environment by using SET with a variable name and no value.
- Registry values of type REG_DWORD are extracted and used in hexadecimal mode.
- File Mode supports the parsing of CR-LF text files only.