Setx


Applies To: Windows Server 2008,Windows Vista

Creates or modifies environment variables in the user or system environment, without requiring programming or scripting. The Setx command also retrieves the values of registry keys and writes them to text files.

For examples of how to use this command, see Examples.

Syntax


Copy Code

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>]

Parameters

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. The path uses the following syntax:

\<HIVE>\<KEY>\...\<Value>

For example, you might specify the following path:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName

/f <File name>

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 from String 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.

Remarks

Examples

To set the MACHINE environment variable in the local environment to the value Brand1, type:


Copy Code

setx MACHINE Brand1

To set the MACHINE environment variable in the system environment to the value Brand1 Computer, type:


Copy Code

setx MACHINE "Brand1 Computer" /m

To set the MYPATH environment variable in the local environment to use the search path defined in the PATH environment variable, type:


Copy Code

setx MYPATH %PATH%

To set the MYPATH environment variable in the local environment to use the search path defined in the PATH environment variable after replacing ~ with %, type:


Copy Code

setx MYPATH ~PATH~

To set the MACHINE environment variable in the local environment to Brand1 on a remote computer named Computer1, type:


Copy Code

setx /s computer1 /u maindom\hiropln /p p@ssW23 MACHINE Brand1

To set the MYPATH environment variable in the local environment to use the search path defined in the PATH environment variable on a remote computer named Computer1, type:


Copy Code

setx /s computer1 /u maindom\hiropln /p p@ssW23 MYPATH %PATH%

To set the TZONE environment variable in the local environment to the value found in the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName registry key, type:


Copy Code

setx TZONE /k HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName

To set the TZONE environment variable in the local environment of a remote computer named Computer1 to the value found in the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName registry key, type:


Copy Code

setx /s computer1 /u maindom\hiropln /p p@ssW23 TZONE /k HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName

To set the BUILD environment variable in the system environment to the value found in the HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber registry key, type:


Copy Code

setx BUILD /k "HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber" /m

To set the BUILD environment variable in the system environment of a remote computer named Computer1 to the value found in the HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber registry key, type:


Copy Code

setx /s computer1 /u maindom\hiropln /p p@ssW23  BUILD /k "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\CurrentBuildNumber" /m

To display the contents of a file named Ipconfig.out, along with the contents' corresponding coordinates, type:


Copy Code

setx /f ipconfig.out /x

To set the IPADDR environment variable in the local environment to the value found at the coordinate 5,11 in the file Ipconfig.out, type:


Copy Code

setx IPADDR /f ipconfig.out /a 5,11

To set the OCTET1 environment variable in the local environment to the value found at the coordinate 5,3 in the file Ipconfig.out with delimiters "#$*.", type:


Copy Code

setx OCTET1 /f ipconfig.out /a 5,3 /d "#$*."

To set the IPGATEWAY environment variable in the local environment to the value found at the coordinate 0,7 with respect to the coordinate of "Gateway" in the file Ipconfig.out, type:


Copy Code

setx IPGATEWAY /f ipconfig.out /r 0,7 Gateway

To display the contents of a file named Ipconfig.out — along with the contents' corresponding coordinates — on a computer named Computer1, type:


Copy Code

setx /s computer1 /u maindom\hiropln /p p@ssW23 /f ipconfig.out /x

Additional references

Command-Line Syntax Key