Environment Variables in Windows (Vista, XP)

See http://www.vistaonwindows.com/environment_variables.php

Sometimes it is desirable to edit certain of the environment variables such as %PATH%. Or it may be useful to create a user-defined environment variable. Vista contains a command-line method SETX that provides a variety of options. It can be used to either create or modify environment variables. Variables can be in the user or the system environment. The command has a number of switches that make it useful in scripts. (Needs administrator privileges.)

Environment variables can also be edited directly in the Registry. They are stored in the same Registry keys as they are in Windows XP. System variables are in the key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
User-specific variables are in


SetX has three ways of working:

Syntax 1:

  SETX [/S system [/U [domain\]user [/P [password]]]] var value [/M]

Syntax 2:

  SETX [/S system [/U [domain\]user [/P [password]]]] var /K regpath [/M]

Syntax 3:

  SETX [/S system [/U [domain\]user [/P [password]]]]
       /F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]


  Creates or modifies environment variables in the user or system
  environment. Can set variables based on arguments, regkeys or
  file input.

Parameter List:

  /S     system          Specifies the remote system to connect to.
  /U     [domain\]user   Specifies the user context under which
                         the command should execute.
  /P     [password]      Specifies the password for the given
                         user context. Prompts for input if omitted.
  var                    Specifies the environment variable to set.
  value                  Specifies a value to be assigned to the
                         environment variable.
  /K     regpath         Specifies that the variable is set based
                         on information from a registry key.
                         Path should be specified in the format of
                         hive\key\...\value. For example,
  /F     file            Specifies the filename of the text file
                         to use.
  /A     x,y             Specifies absolute file coordinates
                         (line X, item Y) as parameters to search
                         within the file.
  /R     x,y string      Specifies relative file coordinates with
                         respect to "string" as the search parameters.
  /M                     Specifies that the variable should be set in
                         the system wide (HKEY_LOCAL_MACHINE)
                         environment. The default is to set the
                         variable under the HKEY_CURRENT_USER
  /X                     Displays file contents with x,y coordinates.
  /D     delimiters      Specifies additional delimiters such as ","
                         or "\". The 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 built-in delimiters, is 15.
  /?                     Displays this help message.

NOTE: 1) SETX writes variables to the master environment in the registry.

    2) On a local system, variables created or modified by this tool
       will be available in future command windows but not in the
       current CMD.exe command window.
    3) On a remote system, variables created or modified by this tool
       will be available at the next logon session.
    4) The valid Registry Key data types are REG_DWORD, REG_EXPAND_SZ,
    5) Supported hives:  HKEY_LOCAL_MACHINE (HKLM),
    6) Delimiters are case sensitive.
    7) REG_DWORD values are extracted from the registry in decimal


  SETX /S system /U user /P password  MACHINE COMPAQ
  SETX /S system /U user /P password MYPATH ^%PATH^%
  SETX TZONE /K HKEY_LOCAL_MACHINE\System\CurrentControlSet\
  SETX BUILD /K "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
       NT\CurrentVersion\CurrentBuildNumber" /M
  SETX /S system /U user /P password TZONE /K HKEY_LOCAL_MACHINE\
  SETX /S system /U user /P password  BUILD /K
       "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\
       CurrentVersion\CurrentBuildNumber" /M
  SETX /F ipconfig.out /X
  SETX IPADDR /F ipconfig.out /A 5,11
  SETX OCTET1 /F ipconfig.out /A 5,3 /D "#$*."
  SETX IPGATEWAY /F ipconfig.out /R 0,7 Gateway
  SETX /S system /U user /P password  /F c:\ipconfig.out /X
Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Comments are closed.

%d bloggers like this: