This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Creates or modifies environment variables in the user or system environment, without requiring programming or scripting. TheSetx command also retrieves the values of registry keys and writes them to text files.
Note
This command provides the only command-line or programmatic way to directly and permanently set system environment values. System environment variables are manually configurable throughControl Panel or through a registry editor. Theset command, which is internal to the command interpreter (Cmd.exe), sets user environment variables for the current console window only.
setx [/s <computer> [/u [<domain>\]<user name> [/p [<password>]]]] <variable> <value> [/m]setx [/s <computer> [/u [<domain>\]<user name> [/p [<password>]]]] <variable>] /k <path> [/m]setx [/s <computer> [/u [<domain>\]<user name> [/p [<password>]]]] /f <filename> {[<variable>] {/a <X>,<Y> | /r <X>,<Y> <String>} [/m] | /x} [/d <delimiters>]| Parameter | Description |
|---|---|
/s<computer> | Specifies the name or IP address of a remote computer. Do not use backslashes. The default value is the name of the local computer. |
/u[<domain>\]<user name> | Runs the script with the credentials of the specified user account. The default value is the system permissions. |
/p [<password>] | Specifies the password of the user account that is specified in the/u parameter. |
<variable> | Specifies the name of the environment variable that you want to set. |
<value> | Specifies the value to which you want to set the environment variable. |
/k<path> | Specifies that the variable is set based on information from a registry key. Thepath uses the following syntax:\\<HIVE>\<KEY>\...\<Value>. For example, you might specify the following path:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName |
/f<filename> | Specifies the file that you want to use. |
/a<X>,<Y> | Specifies absolute coordinates and offset as search parameters. |
/r<X>,<Y> <String> | Specifies relative coordinates and offset fromString as search parameters. |
| /m | Specifies to set the variable in the system environment. The default setting is the local environment. |
| /x | Displays file coordinates, ignoring the/a,/r, and/d command-line options. |
/d<delimiters> | Specifies delimiters such as, or\ to be used in addition to the four built-in delimiters — SPACE, TAB, ENTER, and LINEFEED. Valid delimiters include any ASCII character. The maximum number of delimiters is 15, including built-in delimiters. |
| /? | Displays help at the command prompt. |
This command is similar to the UNIX utility SETENV.
You can use this command to set values for user and system environment variables from one of three sources (modes): Command Line Mode, Registry Mode, or File Mode.
This command writes variables to the master environment in the registry. Variables set withsetx variables are available in future command windows only, not in the current command window.
HKEY_CURRENT_USER andHKEY_LOCAL_MACHINE are the only supported hives. REG_DWORD, REG_EXPAND_SZ, REG_SZ, and REG_MULTI_SZ are the validRegKey data types.
If you gain access toREG_MULTI_SZ values in the registry, only the first item is extracted and used.
You can't use this command to remove values added to the local or system environments. You can use this command with a variable name and no value to remove a corresponding value from the local environment.
REG_DWORD registry values are extracted and used in hexadecimal mode.
File mode supports the parsing of carriage return and line feed (CRLF) text files only.
Running this command on an existing variable removes any variable references and uses expanded values.
For instance, if the variable %PATH% has a reference to %JAVADIR%, and %PATH% is manipulated usingsetx, %JAVADIR% is expanded and its value is assigned directly to the target variable %PATH%. This means that future updates to %JAVADIR%will not be reflected in the %PATH% variable.
Be aware there's a limit of 1024 characters when assigning contents to a variable usingsetx.
This means that the content is cropped if you go over 1024 characters, and that the cropped text is what's applied to the target variable. If this cropped text is applied to an existing variable, it can result in loss of data previously held by the target variable.
To set theMACHINE environment variable in the local environment to the valueBrand1, type:
setx MACHINE Brand1To set theMACHINE environment variable in the system environment to the valueBrand1 Computer, type:
setx MACHINE Brand1 Computer /mTo set theMYPATH environment variable in the local environment to use the search path defined in thePATH environment variable, type:
setx MYPATH %PATH%To set theMYPATH environment variable in the local environment to use the search path defined in thePATH environment variable after replacing~ with%, type:
setx MYPATH ~PATH~To set theMACHINE environment variable in the local environment toBrand1 on a remote computer namedcomputer1, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 MACHINE Brand1To set theMYPATH environment variable in the local environment to use the search path defined in thePATH environment variable on a remote computer namedcomputer1, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 MYPATH %PATH%To set theTZONE environment variable in the local environment to the value found in theHKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName registry key, type:
setx TZONE /k HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardNameTo set theTZONE environment variable in the local environment of a remote computer namedcomputer1 to the value found in theHKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName registry key, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 TZONE /k HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardNameTo set theBUILD environment variable in the system environment to the value found in theHKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber registry key, type:
setx BUILD /k HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber /mTo set the BUILD environment variable in the system environment of a remote computer named Computer1 to the value found in theHKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber registry key, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 BUILD /k HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\CurrentBuildNumber /mTo display the contents of a file namedIpconfig.out, along with the contents' corresponding coordinates, type:
setx /f ipconfig.out /xTo set theIPADDR environment variable in the local environment to the value found at the coordinate5,11 in theIpconfig.out file, type:
setx IPADDR /f ipconfig.out /a 5,11To set theOCTET1 environment variable in the local environment to the value found at the coordinate5,3 in theIpconfig.out file with delimiters#$*., type:
setx OCTET1 /f ipconfig.out /a 5,3 /d #$*.To set theIPGATEWAY environment variable in the local environment to the value found at the coordinate0,7 with respect to the coordinate ofGateway in theIpconfig.out file, type:
setx IPGATEWAY /f ipconfig.out /r 0,7 GatewayTo display the contents of theIpconfig.out file, along with the contents' corresponding coordinates, on a computer namedcomputer1, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 /f ipconfig.out /xWas this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?