¿Dónde se almacenan las variables de entorno en el registro?


Necesito acceder a una variable de entorno de forma remota. Para hacer esto creo que la mejor manera es leerlo desde el registro.

¿Dónde se almacenan las variables de entorno en el registro?

Author: Brian R. Bondy, 2009-02-22

4 answers

Aquí es donde se almacenan en XP a través de Server 2012 R2:

Variables de usuario

HKEY_CURRENT_USER\Environment

Variables del sistema

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
 259
Author: Steve Scheffler,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-31 00:45:33

Me doy cuenta de que esto es viejo, pero hay una forma más eficiente de hacer esto en Windows 7. SETX está instalado de forma predeterminada y admite la conexión a otros sistemas.

Para modificar las variables de entorno globales de un sistema remoto se usaría

setx /m /s HOSTNAME-GOES-HERE VariableNameGoesHere VariableValueGoesHere

Esto no requiere reiniciar el explorador.

 18
Author: Mokilok,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-09 10:43:54

Siempre tuve problemas con eso, hice un getx.mtd:

::getx %envvar% [\m]
::reads envvar from user enviroment variable and stores it in getxvalue variable
::with \m read system enviroment

@SETLOCAL EnableDelayedExpansion
@echo OFF

@set l_regpath="HKEY_CURRENT_USER\Environment"
@if "\m"=="%2" set l_regpath="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

::REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH /t REG_SZ /f /d "%PATH%"
::@REG QUERY %l_regpath% /v %1 /S

@FOR /F "tokens=*" %%A IN ('REG QUERY %l_regpath% /v %1 /S') DO (
@  set l_a=%%A
@   if NOT "!l_a!"=="!l_a:    =!" set l_line=!l_a! 
)

::delimiter is four spaces change it to tab \t
@set l_line=!l_line!
@set l_line=%l_line:    =   %

@set getxvalue=

@FOR /F "tokens=3* delims=  " %%A IN ("%l_line%") DO (
@   set getxvalue=%%A
)
@set getxvalue=!getxvalue!
@echo %getxvalue% > getxfile.tmp.txt
@ENDLOCAL

::we already used tab as delimiter
@FOR /F "delims=    " %%A IN (getxfile.tmp.txt) DO (
    @set getxvalue=%%A
)
@del getxfile.tmp.txt

@echo ON
 4
Author: fantastory,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-20 06:41:41

Cmd:

reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
reg query HKEY_CURRENT_USER\Environment

Powershell:

Get-Item "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
Get-Item HKCU:\Environment

Powershell/. NET: (véase https://msdn.microsoft.com/en-us/library/system.environmentvariabletarget(v=vs. 110).aspx)

[System.Environment]::GetEnvironmentVariables([System.EnvironmentVariableTarget]::Machine)
[System.Environment]::GetEnvironmentVariables([System.EnvironmentVariableTarget]::User)
 1
Author: masterxilo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-07 11:17:27