setx
permanently modifies environment variables.
set
only makes variables available during batch script duration.
Is there any way to set a
Ok I found a much simpler (and obviously less hacky) way than the JScript method, but it put us in the right direction with the volatile environment manipulation.
Simply use the reg
command to manipulate the volatile environment in the registry :
reg add "HKCU\Volatile Environment" /v "%MYVAR%" /d "%MYVALUE%" /f
reg add
both can create and update the value.
\f
bypasses the overwrite confirmation.
Setting an empty data with \d ""
is equivalent to deleting the global variable. You won't see it in the shell with set
, but you can still see it being empty in the registry.
Here is a reference: https://ss64.com/nt/reg.html