2 * initenv.c - Environment initialization
4 * ReactOS Operating System
6 * --------------------------------------------------------------------
8 * This software is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This software is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this software; see the file COPYING.LIB. If not, write
20 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
23 * --------------------------------------------------------------------
33 PWSTR SmSystemEnvironment
= NULL
;
39 SmCreateEnvironment(VOID
)
41 return RtlCreateEnvironment(FALSE
, &SmSystemEnvironment
);
46 SmpSetEnvironmentVariable(IN PVOID Context
,
50 UNICODE_STRING EnvVariable
;
51 UNICODE_STRING EnvValue
;
53 RtlInitUnicodeString(&EnvVariable
,
55 RtlInitUnicodeString(&EnvValue
,
57 return RtlSetEnvironmentVariable(Context
,
63 static NTSTATUS STDCALL
64 SmpEnvironmentQueryRoutine(IN PWSTR ValueName
,
69 IN PVOID EntryContext
)
71 DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName
, ValueType
, ValueLength
);
73 if (ValueType
!= REG_SZ
&& ValueType
!= REG_EXPAND_SZ
)
74 return STATUS_SUCCESS
;
76 DPRINT("ValueData '%S'\n", (PWSTR
)ValueData
);
77 return SmpSetEnvironmentVariable(Context
,ValueName
,ValueData
);
82 SmSetEnvironmentVariables(VOID
)
84 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
85 WCHAR ValueBuffer
[MAX_PATH
];
89 * The following environment variables must be set prior to reading
90 * other variables from the registry.
92 * Variables (example):
93 * SystemRoot = "C:\reactos"
97 /* Copy system root into value buffer */
99 SharedUserData
->NtSystemRoot
);
101 /* Set SystemRoot = "C:\reactos" */
102 SmpSetEnvironmentVariable(&SmSystemEnvironment
, L
"SystemRoot", ValueBuffer
);
104 /* Cut off trailing path */
107 /* Set SystemDrive = "C:" */
108 SmpSetEnvironmentVariable(&SmSystemEnvironment
, L
"SystemDrive", ValueBuffer
);
110 /* Read system environment from the registry. */
111 RtlZeroMemory(&QueryTable
,
114 QueryTable
[0].QueryRoutine
= SmpEnvironmentQueryRoutine
;
116 Status
= RtlQueryRegistryValues(RTL_REGISTRY_CONTROL
,
117 L
"Session Manager\\Environment",
119 &SmSystemEnvironment
,
120 SmSystemEnvironment
);
125 /**********************************************************************
126 * Set environment variables from registry
129 SmUpdateEnvironment(VOID
)
132 return STATUS_SUCCESS
;