1

Ahead of time I am a newb at programming/scripting. I mainly research what I want and just edit it to fit my needs when possible.

Environment:

  • Windows 7
  • CMD
  • Usergroup = admin
  • Occurs when launching as user(admin) or launching cmd as administrator

When I use CMD to change an environment setting, it does not save to the system. Example:

C:\Users\admin>SET TESTVARIABLE = "This is a test"
C:\Users\admin>SET
    TESTVARIABLE = "This is a test"
C:\Users\admin>_

close out cmd, reopen, use SET and the testvariable is no longer there. Going through System > Advanced System Settings > Environment Variables > System Variables is the only way I can positively make changes to the variables.

This is also affected by any .bat files I make. Mine don't actually get applied when they run but other peoples that I copy(entire .bat file, not just text/context).

This is occuring on my (all at work) desk pc(win10) and 2x Remote Desktop (win7). I am admin and I'm using admin users on these RDP's.

Anyone have any idea what is happening, what i'm missing, how I can research it or fix it?

  • 3
    Type `SETX /?` at the command prompt. – Compo Jan 06 '17 at 15:42
  • It worked now, but in the wrong spot. I'm able to see it saved in CMD with `set` but when I look at the system variables, it's not there. It does appear in 'User variables for admin' but that is not where I need it. I'm guessing there is switch(?) or delimiter(?) – Quantim_Mittens Jan 06 '17 at 15:55
  • What do yo mean with wrong spot? BTW the spaces around the equal sign in `SET TESTVARIABLE = "This is a test"` become part of the var name and the content. –  Jan 06 '17 at 15:58
  • 1
    See the `/M` switch of setx. And READING `setx /?` would have helped. –  Jan 06 '17 at 16:01
  • Thank you, didn't know about the spaces being read that way. about reading the `setx /?` contents: I get lost any time they provide an example. I have no idea what they want when it reads 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] – Quantim_Mittens Jan 06 '17 at 16:05
  • The `/M` option seems crystal clear. This is straight from the help file that you also copied and pasted from. **/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 environment.** – Squashman Jan 06 '17 at 17:32

1 Answers1

1

Variables set using the "set" command are only available in the cmd's instance. To save variables persistently see this: Set a persistent environment variable from cmd.exe

Community
  • 1
  • 1
user538331
  • 64
  • 4
  • Thank you, this gave a wonderful explanation. Now, do you possibly know of a guide or info on how to interpret the `$command /?` examples? b/c as LotPings stated, I need to read them but they are very confusing to me when they give examples. – Quantim_Mittens Jan 06 '17 at 16:21
  • It's actually not that hard. All parameters the setx commands needs which are surrounded by [] are optional everything else is required. The parameters itself are explained below the syntax and description. I recommend using this site as your reference in terms of cmd.exe (besides the built-in help via /?): http://ss64.com/nt – user538331 Jan 06 '17 at 20:35