Setx
Set environment variables in the local or system environment without writing programs or making scripts. Setx also retrieves the value of a registry key and writes it to a text file.
Syntax
setx User ]]] VariableValue
setx User ]]] /k Path
setx User ]]] /f FileName { {/a X,y | /r X,y "String"} | /x}
Parameters
/s Computer
Specifies the remote computer name or IP address (no backslashes allowed). The default is the local computer. This parameter applies to all files and folders specified in the command.
/u User
Runs the script with the permissions of the specified user account. The default is system permissions.
/p
Specifies the password for the user account specified in the /u parameter.
Variable
Specifies the name of the environment variable to set.
Value
Specifies the value to set the environment variable to.
/k Path
Specifies to set the variable based on information from a registry key. Specify Path in the format \HIVE\KEY\...\Value (for example, HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName).
/f FileName
Specifies 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.
/m
Specifies to set Variable in the system environment. The default is the local environment.
/x
Displays the file coordinates. Ignores the /a, /r, and /d command-line options.
/d Delimiters
Specifies additional delimiters, such as "," or "\". The four built-in delimiters are space, tab, carriage return, and line feed. Any ASCII character can be used as an additional delimiter. The maximum number of delimiters is 15, including the four built-in ones.
/?
Displays help at the command prompt.
Remarks
• Use the /s, /u, and /p command-line options. The /u and /p command-line options are only available when using /s. You must use both /p and /u to provide the user password.
• Setx provides a way to directly and permanently set system environment values for command-line or programming purposes. System environment variables can be manually configured through "Control Panel" or through the Registry Editor (Regedit.exe). The Set command is an internal command of the command interpreter (i.e., Cmd.exe) and only sets 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.
• Setx is similar to the UNIX utility SETENV.
• Setx writes variables to the main environment in the registry. Variables set with setx are only available in future command windows, not in the current command window.
• Only the HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE hives are supported. REG_DWORD, REG_EXPAND_SZ, REG_SZ, and REG_MULTI_SZ are valid RegKey data types.
• When accessing a REG_MULTI_SZ value in the registry, only the first item is expanded and used.
• Values added to the local or system environment cannot be deleted using setx. You can use set with a variable name but no value to delete the corresponding value in the local environment.
• REG_DWORD registry values are expanded and used in hexadecimal mode.
• File mode only supports parsing CR-LF text files.
Examples
To set the MACHINE environment variable to Brand1 in the local environment, type:
setx MACHINE brand1
To set the MACHINE environment variable to Brand1 Computer in the system environment, type:
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:
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:
setx MYPATH ~PATH~
To set the MACHINE environment variable in the local environment to BRAND1 on a computer named Computer1, type:
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 computer named Computer1, type:
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:
setx 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:
setx BUILD /k "HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber" /m
To set the TZONE environment variable in the local environment on a computer named Computer1 to the value found in the HKEY_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\StandardName
To set the BUILD environment variable in the system environment on a computer named Computer1 to the value found in the HKEY_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" /m
To display the contents of the file ipconfig.out and its corresponding coordinates, type:
setx /f ipconfig.out /x
To set the IPADDR environment variable in the local environment to the value found at coordinates 5,11 in the file ipconfig.out, type:
setx IPADDR /f ipconfig.out /a 5,11
To set the OCTET1 environment variable in the local environment to the value found at coordinates 5,3 in the file ipconfig.out with delimiters "#$*.", type:
setx OCTET1 /f ipconfig.out /a 5,3 /d "#$*."
To set the IPGATEWAY environment variable in the local environment to the value found at coordinates 0,7 relative to "Gateway" in the file ipconfig.out, type:
setx IPGATEWAY /f ipconfig.out /r 0,7 Gateway
To display the contents of the file ipconfig.out and its corresponding coordinates on a computer named Computer1, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 /f ipconfig.out /x
Set environment variables in the local or system environment without writing programs or making scripts. Setx also retrieves the value of a registry key and writes it to a text file.
Syntax
setx User ]]] VariableValue
setx User ]]] /k Path
setx User ]]] /f FileName { {/a X,y | /r X,y "String"} | /x}
Parameters
/s Computer
Specifies the remote computer name or IP address (no backslashes allowed). The default is the local computer. This parameter applies to all files and folders specified in the command.
/u User
Runs the script with the permissions of the specified user account. The default is system permissions.
/p
Specifies the password for the user account specified in the /u parameter.
Variable
Specifies the name of the environment variable to set.
Value
Specifies the value to set the environment variable to.
/k Path
Specifies to set the variable based on information from a registry key. Specify Path in the format \HIVE\KEY\...\Value (for example, HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName).
/f FileName
Specifies 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.
/m
Specifies to set Variable in the system environment. The default is the local environment.
/x
Displays the file coordinates. Ignores the /a, /r, and /d command-line options.
/d Delimiters
Specifies additional delimiters, such as "," or "\". The four built-in delimiters are space, tab, carriage return, and line feed. Any ASCII character can be used as an additional delimiter. The maximum number of delimiters is 15, including the four built-in ones.
/?
Displays help at the command prompt.
Remarks
• Use the /s, /u, and /p command-line options. The /u and /p command-line options are only available when using /s. You must use both /p and /u to provide the user password.
• Setx provides a way to directly and permanently set system environment values for command-line or programming purposes. System environment variables can be manually configured through "Control Panel" or through the Registry Editor (Regedit.exe). The Set command is an internal command of the command interpreter (i.e., Cmd.exe) and only sets 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.
• Setx is similar to the UNIX utility SETENV.
• Setx writes variables to the main environment in the registry. Variables set with setx are only available in future command windows, not in the current command window.
• Only the HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE hives are supported. REG_DWORD, REG_EXPAND_SZ, REG_SZ, and REG_MULTI_SZ are valid RegKey data types.
• When accessing a REG_MULTI_SZ value in the registry, only the first item is expanded and used.
• Values added to the local or system environment cannot be deleted using setx. You can use set with a variable name but no value to delete the corresponding value in the local environment.
• REG_DWORD registry values are expanded and used in hexadecimal mode.
• File mode only supports parsing CR-LF text files.
Examples
To set the MACHINE environment variable to Brand1 in the local environment, type:
setx MACHINE brand1
To set the MACHINE environment variable to Brand1 Computer in the system environment, type:
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:
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:
setx MYPATH ~PATH~
To set the MACHINE environment variable in the local environment to BRAND1 on a computer named Computer1, type:
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 computer named Computer1, type:
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:
setx 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:
setx BUILD /k "HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber" /m
To set the TZONE environment variable in the local environment on a computer named Computer1 to the value found in the HKEY_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\StandardName
To set the BUILD environment variable in the system environment on a computer named Computer1 to the value found in the HKEY_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" /m
To display the contents of the file ipconfig.out and its corresponding coordinates, type:
setx /f ipconfig.out /x
To set the IPADDR environment variable in the local environment to the value found at coordinates 5,11 in the file ipconfig.out, type:
setx IPADDR /f ipconfig.out /a 5,11
To set the OCTET1 environment variable in the local environment to the value found at coordinates 5,3 in the file ipconfig.out with delimiters "#$*.", type:
setx OCTET1 /f ipconfig.out /a 5,3 /d "#$*."
To set the IPGATEWAY environment variable in the local environment to the value found at coordinates 0,7 relative to "Gateway" in the file ipconfig.out, type:
setx IPGATEWAY /f ipconfig.out /r 0,7 Gateway
To display the contents of the file ipconfig.out and its corresponding coordinates on a computer named Computer1, type:
setx /s computer1 /u maindom\hiropln /p p@ssW23 /f ipconfig.out /x
Recent Ratings for This Post
( 1 in total)
Click for details
| Rater | Score | Time |
|---|---|---|
| redtek | +3 | 2006-12-07 08:23 |
bat c c++
