From 0a19a07ecf4ac50ad8d758a82f9a4259b5fcc248 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 5 May 2004 22:05:18 +0000 Subject: [PATCH] Set additional environment variables at startup from HKLM\System\CurrentControlSet\Control\Session Manager\Environment. --- dlls/kernel/process.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/dlls/kernel/process.c b/dlls/kernel/process.c index ffca8f4caf..51c35cb6d1 100644 --- a/dlls/kernel/process.c +++ b/dlls/kernel/process.c @@ -400,6 +400,56 @@ static BOOL build_initial_environment( char **environ ) } +/*********************************************************************** + * set_registry_environment + * + * Set the environment variables specified in the registry. + */ +static void set_registry_environment(void) +{ + static const WCHAR env_keyW[] = {'M','a','c','h','i','n','e','\\', + 'S','y','s','t','e','m','\\', + 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\', + 'C','o','n','t','r','o','l','\\', + 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\', + 'E','n','v','i','r','o','n','m','e','n','t',0}; + OBJECT_ATTRIBUTES attr; + UNICODE_STRING nameW, env_name, env_value; + NTSTATUS status; + HKEY hkey; + DWORD size; + int index; + char buffer[1024 + sizeof(KEY_VALUE_FULL_INFORMATION)]; + KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer; + + attr.Length = sizeof(attr); + attr.RootDirectory = 0; + attr.ObjectName = &nameW; + attr.Attributes = 0; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + RtlInitUnicodeString( &nameW, env_keyW ); + if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS) return; + + for (index = 0; ; index++) + { + status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation, + buffer, sizeof(buffer), &size ); + if (status == STATUS_BUFFER_OVERFLOW) continue; + if (status != STATUS_SUCCESS) break; + if (info->Type != REG_SZ) continue; /* FIXME: handle REG_EXPAND_SZ */ + env_name.Buffer = info->Name; + env_name.Length = env_name.MaximumLength = info->NameLength; + env_value.Buffer = (WCHAR *)(buffer + info->DataOffset); + env_value.Length = env_value.MaximumLength = info->DataLength; + if (env_value.Length && !env_value.Buffer[env_value.Length/sizeof(WCHAR)-1]) + env_value.Length--; /* don't count terminating null if any */ + RtlSetEnvironmentVariable( NULL, &env_name, &env_value ); + } + NtClose( hkey ); +} + + /*********************************************************************** * set_library_wargv * @@ -750,6 +800,8 @@ static BOOL process_init( char *argv[], char **environ ) } SERVER_END_REQ; + if (!info_size) set_registry_environment(); + return TRUE; } -- 2.32.0.93.g670b81a890