Setting a system environment variable from command line in Windows Server 2012 R2

Are you asking if it is potential to set a environment variable at the system charge from a command immediate in Windows Server 2012 R2 ? The answer is YES. I am for example trying to set system variables for my Amazon ACCESS and SECRET key so I can utilize the Amazon CLI tools. You can add User or System variables via GUI :

  • Press “Windows-Key+X” and select  System
  • Select Advanced System Properties
  • Select Environment Settings
  • Now you can add User or System variables

other manner is to use childlike command line and save few click for your self 🙂

  • Open CMD.exe and run as Administrator

To add user variable such as JAVA_HOME=C : \Program Files ( x86 ) \Java\jre

setx JAVA_HOME "C:\Program FIles (x86)\Java\jre"

To add arrangement variables you have to use interchange -m in the control tune

setx -m AMAZON_ACCESS_KEY "012343456789"
setx -m AMAZON_SECRET_KEY "vmadvgjhgsdjgsdiiuuygdisggksgd"

If you check the variables via GUI way – you will see that these variables are added in the right position. I am indisputable now you think that this can be scripted – yes it can. easily you can create a batch file with those variables and run ampere Administrator to apply them into your system.

About the utility – you can find it in Windows 8, Windows Server 2012 R2 :

C:\setx /?
    Creates or modifies environment variables in the user or system
    environment. Can set variables based on arguments, regkeys or
    file input.
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,
         REG_SZ, REG_MULTI_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

Have one with this utility !

source :
Category : Tech

About admin

I am the owner of the website, my purpose is to bring all the most useful information to users.

Check Also


Manage participants in a zoom meeting webinar

Call the people who attend the meet as follows Alternate host host Who scheduled the …

Leave a Reply

Your email address will not be published.