3 * initenv.c - Environment initialization
5 * ReactOS Operating System
7 * --------------------------------------------------------------------
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
24 * --------------------------------------------------------------------
34 PWSTR SmSystemEnvironment
= NULL
;
40 SmCreateEnvironment(VOID
)
42 return RtlCreateEnvironment(FALSE
, &SmSystemEnvironment
);
47 SmpSetEnvironmentVariable(PVOID Context
,
51 UNICODE_STRING EnvVariable
;
52 UNICODE_STRING EnvValue
;
54 RtlInitUnicodeString(&EnvVariable
,
56 RtlInitUnicodeString(&EnvValue
,
58 RtlSetEnvironmentVariable(Context
,
62 return(STATUS_SUCCESS
);
66 static NTSTATUS STDCALL
67 SmpEnvironmentQueryRoutine(PWSTR ValueName
,
74 DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName
, ValueType
, ValueLength
);
75 DPRINT("ValueData '%S'\n", (PWSTR
)ValueData
);
77 if (ValueType
!= REG_SZ
)
79 return(STATUS_SUCCESS
);
81 return SmpSetEnvironmentVariable(Context
,ValueName
,ValueData
);
86 SmSetEnvironmentVariables(VOID
)
88 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
89 WCHAR ValueBuffer
[MAX_PATH
];
93 * The following environment variables must be set prior to reading
94 * other variables from the registry.
96 * Variables (example):
97 * SystemRoot = "C:\reactos"
101 /* Copy system root into value buffer */
103 SharedUserData
->NtSystemRoot
);
105 /* Set SystemRoot = "C:\reactos" */
106 SmpSetEnvironmentVariable(&SmSystemEnvironment
,L
"SystemRoot",ValueBuffer
);
108 /* Cut off trailing path */
111 /* Set SystemDrive = "C:" */
112 SmpSetEnvironmentVariable(&SmSystemEnvironment
,L
"SystemDrive",ValueBuffer
);
114 /* Read system environment from the registry. */
115 RtlZeroMemory(&QueryTable
,
118 QueryTable
[0].QueryRoutine
= SmpEnvironmentQueryRoutine
;
120 Status
= RtlQueryRegistryValues(RTL_REGISTRY_CONTROL
,
121 L
"\\Session Manager\\Environment",
123 &SmSystemEnvironment
,
124 SmSystemEnvironment
);
129 /**********************************************************************
130 * Set environment variables from registry
133 SmUpdateEnvironment(VOID
)
136 return STATUS_SUCCESS
;