ReactOS 0.4.17-dev-1196-gb6224c3
environment.c
Go to the documentation of this file.
1/*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19/*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS system libraries
22 * FILE: dll/win32/userenv/environment.c
23 * PURPOSE: User environment functions
24 * PROGRAMMER: Eric Kohl
25 */
26
27#include "precomp.h"
28
29#define NDEBUG
30#include <debug.h>
31
32static
33BOOL
36 LPWSTR lpValue,
37 BOOL bExpand)
38{
41 UNICODE_STRING SrcValue, DstValue;
45
46 if (bExpand)
47 {
48 RtlInitUnicodeString(&SrcValue, lpValue);
49
50 Length = 2 * MAX_PATH * sizeof(WCHAR);
51
52 DstValue.Length = 0;
53 DstValue.MaximumLength = Length;
54 DstValue.Buffer = Buffer = LocalAlloc(LPTR, Length);
55 if (DstValue.Buffer == NULL)
56 {
57 DPRINT1("LocalAlloc() failed\n");
58 return FALSE;
59 }
60
62 &SrcValue,
63 &DstValue,
64 &Length);
65 if (!NT_SUCCESS(Status))
66 {
67 DPRINT1("RtlExpandEnvironmentStrings_U() failed (Status %lx)\n", Status);
68 DPRINT1("Length %lu\n", Length);
69
70 if (Buffer)
72
73 return FALSE;
74 }
75 }
76 else
77 {
78 RtlInitUnicodeString(&DstValue, lpValue);
79 }
80
81 if (!_wcsicmp(lpName, L"TEMP") || !_wcsicmp(lpName, L"TMP"))
82 {
84 {
86 }
87 else
88 {
89 DPRINT("GetShortPathNameW() failed for %S (Error %lu)\n", DstValue.Buffer, GetLastError());
90 }
91 }
92
94
95 DPRINT("Value: %wZ\n", &DstValue);
96
98 &Name,
99 &DstValue);
100
101 if (Buffer)
103
104 if (!NT_SUCCESS(Status))
105 {
106 DPRINT1("RtlSetEnvironmentVariable() failed (Status %lx)\n", Status);
107 return FALSE;
108 }
109
110 return TRUE;
111}
112
113
114static
115BOOL
118 LPWSTR lpValue)
119{
122
124
125 Value.Length = 0;
126 Value.MaximumLength = 1024 * sizeof(WCHAR);
127 Value.Buffer = LocalAlloc(LPTR, Value.MaximumLength);
128 if (Value.Buffer == NULL)
129 return FALSE;
130
131 Value.Buffer[0] = UNICODE_NULL;
132
134 &Name,
135 &Value);
136 if (NT_SUCCESS(Status))
138
140
142 &Name,
143 &Value);
144 LocalFree(Value.Buffer);
145 if (!NT_SUCCESS(Status))
146 {
147 DPRINT1("RtlSetEnvironmentVariable() failed (Status %lx)\n", Status);
148 return FALSE;
149 }
150
151 return TRUE;
152}
153
154
155static
156HKEY
158{
159 LONG Error;
160 UNICODE_STRING SidString;
161 HKEY hKey;
162
163 if (!GetUserSidStringFromToken(hToken, &SidString))
164 {
165 DPRINT1("GetUserSidFromToken() failed\n");
166 return NULL;
167 }
168
170 SidString.Buffer,
171 0,
173 &hKey);
174 if (Error != ERROR_SUCCESS)
175 {
176 DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error);
177 RtlFreeUnicodeString(&SidString);
179 return NULL;
180 }
181
182 RtlFreeUnicodeString(&SidString);
183
184 return hKey;
185}
186
187
188static
189BOOL
191 OUT LPWSTR *UserName,
192 OUT LPWSTR *DomainName)
193{
194 BOOL bRet = TRUE;
195 PSID Sid = NULL;
196 LPWSTR lpUserName = NULL;
197 LPWSTR lpDomainName = NULL;
198 DWORD cbUserName = 0;
199 DWORD cbDomainName = 0;
200 SID_NAME_USE SidNameUse;
201
202 Sid = GetUserSid(hToken);
203 if (Sid == NULL)
204 {
205 DPRINT1("GetUserSid() failed\n");
206 return FALSE;
207 }
208
210 Sid,
211 NULL,
212 &cbUserName,
213 NULL,
214 &cbDomainName,
215 &SidNameUse))
216 {
218 {
219 bRet = FALSE;
220 goto done;
221 }
222 }
223
224 lpUserName = LocalAlloc(LPTR, cbUserName * sizeof(WCHAR));
225 if (lpUserName == NULL)
226 {
227 bRet = FALSE;
228 goto done;
229 }
230
231 lpDomainName = LocalAlloc(LPTR, cbDomainName * sizeof(WCHAR));
232 if (lpDomainName == NULL)
233 {
234 bRet = FALSE;
235 goto done;
236 }
237
239 Sid,
240 lpUserName,
241 &cbUserName,
242 lpDomainName,
243 &cbDomainName,
244 &SidNameUse))
245 {
246 bRet = FALSE;
247 goto done;
248 }
249
250 *UserName = lpUserName;
251 *DomainName = lpDomainName;
252
253done:
254 if (bRet == FALSE)
255 {
256 if (lpUserName != NULL)
257 LocalFree(lpUserName);
258
259 if (lpDomainName != NULL)
260 LocalFree(lpDomainName);
261 }
262
263 LocalFree(Sid);
264
265 return bRet;
266}
267
268
269static
270BOOL
272 HKEY hKey,
273 LPWSTR lpSubKeyName)
274{
275 LONG Error;
276 HKEY hEnvKey;
277 DWORD dwValues;
278 DWORD dwMaxValueNameLength;
279 DWORD dwMaxValueDataLength;
280 DWORD dwValueNameLength;
281 DWORD dwValueDataLength;
282 DWORD dwType;
283 DWORD i;
284 LPWSTR lpValueName;
285 LPWSTR lpValueData;
286
288 lpSubKeyName,
289 0,
291 &hEnvKey);
292 if (Error != ERROR_SUCCESS)
293 {
294 DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error);
296 return FALSE;
297 }
298
299 Error = RegQueryInfoKey(hEnvKey,
300 NULL,
301 NULL,
302 NULL,
303 NULL,
304 NULL,
305 NULL,
306 &dwValues,
307 &dwMaxValueNameLength,
308 &dwMaxValueDataLength,
309 NULL,
310 NULL);
311 if (Error != ERROR_SUCCESS)
312 {
313 DPRINT1("RegQueryInforKey() failed (Error %ld)\n", Error);
314 RegCloseKey(hEnvKey);
316 return FALSE;
317 }
318
319 if (dwValues == 0)
320 {
321 RegCloseKey(hEnvKey);
322 return TRUE;
323 }
324
325 /* Allocate buffers */
326 dwMaxValueNameLength++;
327 lpValueName = LocalAlloc(LPTR, dwMaxValueNameLength * sizeof(WCHAR));
328 if (lpValueName == NULL)
329 {
330 RegCloseKey(hEnvKey);
331 return FALSE;
332 }
333
334 lpValueData = LocalAlloc(LPTR, dwMaxValueDataLength);
335 if (lpValueData == NULL)
336 {
337 LocalFree(lpValueName);
338 RegCloseKey(hEnvKey);
339 return FALSE;
340 }
341
342 /* Enumerate values */
343 for (i = 0; i < dwValues; i++)
344 {
345 dwValueNameLength = dwMaxValueNameLength;
346 dwValueDataLength = dwMaxValueDataLength;
347
348 Error = RegEnumValueW(hEnvKey,
349 i,
350 lpValueName,
351 &dwValueNameLength,
352 NULL,
353 &dwType,
354 (LPBYTE)lpValueData,
355 &dwValueDataLength);
356 if (Error == ERROR_SUCCESS)
357 {
358 if (!_wcsicmp(lpValueName, L"PATH"))
359 {
360 /* Append 'Path' environment variable */
362 lpValueName,
363 lpValueData);
364 }
365 else
366 {
367 /* Set environment variable */
369 lpValueName,
370 lpValueData,
371 (dwType == REG_EXPAND_SZ));
372 }
373 }
374 else
375 {
376 LocalFree(lpValueData);
377 LocalFree(lpValueName);
378 RegCloseKey(hEnvKey);
379
380 return FALSE;
381 }
382 }
383
384 LocalFree(lpValueData);
385 LocalFree(lpValueName);
386 RegCloseKey(hEnvKey);
387
388 return TRUE;
389}
390
391
392static
393BOOL
395{
396 LONG Error;
397 HKEY hEnvKey;
398 DWORD dwValues;
399 DWORD dwMaxValueNameLength;
400 DWORD dwMaxValueDataLength;
401 DWORD dwValueNameLength;
402 DWORD dwValueDataLength;
403 DWORD dwType;
404 DWORD i;
405 LPWSTR lpValueName;
406 LPWSTR lpValueData;
407
409 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
410 0,
412 &hEnvKey);
413 if (Error != ERROR_SUCCESS)
414 {
415 DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error);
416 return FALSE;
417 }
418
419 Error = RegQueryInfoKey(hEnvKey,
420 NULL,
421 NULL,
422 NULL,
423 NULL,
424 NULL,
425 NULL,
426 &dwValues,
427 &dwMaxValueNameLength,
428 &dwMaxValueDataLength,
429 NULL,
430 NULL);
431 if (Error != ERROR_SUCCESS)
432 {
433 DPRINT1("RegQueryInforKey() failed (Error %ld)\n", Error);
434 RegCloseKey(hEnvKey);
435 return FALSE;
436 }
437
438 if (dwValues == 0)
439 {
440 RegCloseKey(hEnvKey);
441 return TRUE;
442 }
443
444 /* Allocate buffers */
445 dwMaxValueNameLength++;
446 lpValueName = LocalAlloc(LPTR, dwMaxValueNameLength * sizeof(WCHAR));
447 if (lpValueName == NULL)
448 {
449 RegCloseKey(hEnvKey);
450 return FALSE;
451 }
452
453 lpValueData = LocalAlloc(LPTR, dwMaxValueDataLength);
454 if (lpValueData == NULL)
455 {
456 LocalFree(lpValueName);
457 RegCloseKey(hEnvKey);
458 return FALSE;
459 }
460
461 /* Enumerate values */
462 for (i = 0; i < dwValues; i++)
463 {
464 dwValueNameLength = dwMaxValueNameLength;
465 dwValueDataLength = dwMaxValueDataLength;
466
467 Error = RegEnumValueW(hEnvKey,
468 i,
469 lpValueName,
470 &dwValueNameLength,
471 NULL,
472 &dwType,
473 (LPBYTE)lpValueData,
474 &dwValueDataLength);
475 if (Error == ERROR_SUCCESS)
476 {
477 /* Set environment variable */
479 lpValueName,
480 lpValueData,
481 (dwType == REG_EXPAND_SZ));
482 }
483 else
484 {
485 LocalFree(lpValueData);
486 LocalFree(lpValueName);
487 RegCloseKey(hEnvKey);
488
489 return FALSE;
490 }
491 }
492
493 LocalFree(lpValueData);
494 LocalFree(lpValueName);
495 RegCloseKey(hEnvKey);
496
497 return TRUE;
498}
499
500
501BOOL
502WINAPI
504 IN HANDLE hToken,
505 IN BOOL bInherit)
506{
508 LONG lError;
509 PWSTR* Environment = (PWSTR*)lpEnvironment;
511 DWORD dwType;
512 HKEY hKey;
513 HKEY hKeyUser;
514 LPWSTR lpUserName = NULL;
515 LPWSTR lpDomainName = NULL;
517 WCHAR PublicDirectory[MAX_PATH];
518 WCHAR szValue[1024];
519
520 DPRINT("CreateEnvironmentBlock() called\n");
521
522 if (lpEnvironment == NULL)
523 {
525 return FALSE;
526 }
527
529 if (!NT_SUCCESS(Status))
530 {
531 DPRINT1("RtlCreateEnvironment() failed (Status %lx)\n", Status);
533 return FALSE;
534 }
535
536 /* Set 'SystemRoot' variable */
538 if (GetEnvironmentVariableW(L"SystemRoot", Buffer, Length))
539 {
541 L"SystemRoot",
542 Buffer,
543 FALSE);
544 }
545
546 /* Set 'SystemDrive' variable */
547 if (GetEnvironmentVariableW(L"SystemDrive", Buffer, Length))
548 {
550 L"SystemDrive",
551 Buffer,
552 FALSE);
553 }
554
555 /* Set variables from Session Manager */
557 {
559 return FALSE;
560 }
561
562 /* Set 'COMPUTERNAME' variable */
565 {
567 L"COMPUTERNAME",
568 Buffer,
569 FALSE);
570 }
571
572 /* Set 'ALLUSERSPROFILE' variable */
575 {
577 L"ALLUSERSPROFILE",
578 Buffer,
579 FALSE);
581 L"ProgramData",
582 Buffer,
583 FALSE);
584 }
585
586 /* Set 'USERPROFILE' variable to the default users profile */
589 {
591 L"USERPROFILE",
592 Buffer,
593 TRUE);
594 }
595
597 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
598 0,
599 KEY_READ,
600 &hKey);
601 if (lError == ERROR_SUCCESS)
602 {
603 Length = sizeof(szValue);
604 lError = RegQueryValueExW(hKey,
605 L"ProgramFilesDir",
606 NULL,
607 &dwType,
608 (LPBYTE)szValue,
609 &Length);
610 if (lError == ERROR_SUCCESS)
611 {
613 L"ProgramFiles",
614 szValue,
615 FALSE);
616 }
617
618 Length = sizeof(szValue);
619 lError = RegQueryValueExW(hKey,
620 L"CommonFilesDir",
621 NULL,
622 &dwType,
623 (LPBYTE)szValue,
624 &Length);
625 if (lError == ERROR_SUCCESS)
626 {
628 L"CommonProgramFiles",
629 szValue,
630 FALSE);
631 }
632
634 }
635
636 /* Set 'PUBLIC' variable to the public user directory */
638 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
639 0,
640 KEY_READ,
641 &hKey);
642 if (lError == ERROR_SUCCESS)
643 {
644 Length = sizeof(szValue);
645 lError = RegQueryValueExW(hKey,
646 L"Public",
647 NULL,
648 &dwType,
649 (LPBYTE)szValue,
650 &Length);
651 if (lError == ERROR_SUCCESS)
652 {
653 if (!ExpandEnvironmentStringsW(szValue,
654 PublicDirectory,
655 ARRAYSIZE(PublicDirectory)))
656 {
657 DPRINT1("Error: %lu\n", GetLastError());
659 return FALSE;
660 }
661
662 SetUserEnvironmentVariable(Environment, L"PUBLIC", PublicDirectory, FALSE);
663 }
665 }
666
667 /*
668 * If no user token is specified, the system environment variables are set
669 * and we stop here, otherwise continue setting the user-specific variables.
670 */
671 if (hToken == NULL)
672 return TRUE;
673
674 hKeyUser = GetCurrentUserKey(hToken);
675 if (hKeyUser == NULL)
676 {
677 DPRINT1("GetCurrentUserKey() failed\n");
679 return FALSE;
680 }
681
682 /* Set 'USERPROFILE' variable */
685 {
686 DWORD MinLen = 2;
687
689 L"USERPROFILE",
690 Buffer,
691 FALSE);
692
693 // FIXME: Strangely enough the following two environment variables
694 // are not set by userenv.dll in Windows... See r68284 / CORE-9875
695 // FIXME2: This is done by msgina.dll !!
696
697 /* At least <drive letter>:<path> */
698 if (Length > MinLen)
699 {
700 /* Set 'HOMEDRIVE' variable */
701 StringCchCopyNW(szValue, ARRAYSIZE(Buffer), Buffer, MinLen);
703 L"HOMEDRIVE",
704 szValue,
705 FALSE);
706
707 /* Set 'HOMEPATH' variable */
708 StringCchCopyNW(szValue, ARRAYSIZE(Buffer), Buffer + MinLen, Length - MinLen);
710 L"HOMEPATH",
711 szValue,
712 FALSE);
713 }
714 }
715 else
716 {
717 DPRINT1("GetUserProfileDirectoryW failed with error %lu\n", GetLastError());
718 }
719
720 if (GetUserAndDomainName(hToken,
721 &lpUserName,
722 &lpDomainName))
723 {
724 /* Set 'USERNAME' variable */
726 L"USERNAME",
727 lpUserName,
728 FALSE);
729
730 /* Set 'USERDOMAIN' variable */
732 L"USERDOMAIN",
733 lpDomainName,
734 FALSE);
735
736 if (lpUserName != NULL)
737 LocalFree(lpUserName);
738
739 if (lpDomainName != NULL)
740 LocalFree(lpDomainName);
741 }
742
743 /* Set user environment variables */
745 hKeyUser,
746 L"Environment");
747
748 /* Set user volatile environment variables */
750 hKeyUser,
751 L"Volatile Environment");
752
753 RegCloseKey(hKeyUser);
754
755 return TRUE;
756}
757
758
759BOOL
760WINAPI
762{
763 DPRINT("DestroyEnvironmentBlock() called\n");
764
765 if (lpEnvironment == NULL)
766 {
768 return FALSE;
769 }
770
771 RtlDestroyEnvironment(lpEnvironment);
772
773 return TRUE;
774}
775
776
777BOOL
778WINAPI
780 IN LPCWSTR lpSrc,
781 OUT LPWSTR lpDest,
783{
784 BOOL Ret = FALSE;
785 PVOID lpEnvironment;
786
787 if (lpSrc == NULL || lpDest == NULL || dwSize == 0)
788 {
790 return FALSE;
791 }
792
793 if (CreateEnvironmentBlock(&lpEnvironment,
794 hToken,
795 FALSE))
796 {
797 UNICODE_STRING SrcU, DestU;
799
800 /* Initialize the strings */
801 RtlInitUnicodeString(&SrcU, lpSrc);
802 DestU.Length = 0;
803 DestU.MaximumLength = dwSize * sizeof(WCHAR);
804 DestU.Buffer = lpDest;
805
806 /* Expand the strings */
808 &SrcU,
809 &DestU,
810 NULL);
811
812 DestroyEnvironmentBlock(lpEnvironment);
813
814 if (NT_SUCCESS(Status))
815 {
816 Ret = TRUE;
817 }
818 else
819 {
821 }
822 }
823
824 return Ret;
825}
826
827
828BOOL
829WINAPI
831 IN LPCSTR lpSrc,
832 OUT LPSTR lpDest,
834{
835 BOOL Ret = FALSE;
836 DWORD dwSrcLen;
837 LPWSTR lpSrcW = NULL, lpDestW = NULL;
838
839 if (lpSrc == NULL || lpDest == NULL || dwSize == 0)
840 {
842 return FALSE;
843 }
844
845 dwSrcLen = strlen(lpSrc);
846 lpSrcW = (LPWSTR)GlobalAlloc(GMEM_FIXED,
847 (dwSrcLen + 1) * sizeof(WCHAR));
848 if (lpSrcW == NULL ||
850 0,
851 lpSrc,
852 -1,
853 lpSrcW,
854 dwSrcLen + 1) == 0)
855 {
856 goto Cleanup;
857 }
858
859 lpDestW = (LPWSTR)GlobalAlloc(GMEM_FIXED,
860 dwSize * sizeof(WCHAR));
861 if (lpDestW == NULL)
862 goto Cleanup;
863
865 lpSrcW,
866 lpDestW,
867 dwSize);
868 if (Ret)
869 {
871 0,
872 lpDestW,
873 -1,
874 lpDest,
875 dwSize,
876 NULL,
877 NULL) == 0)
878 {
879 Ret = FALSE;
880 }
881 }
882
883Cleanup:
884 if (lpSrcW != NULL)
885 GlobalFree((HGLOBAL)lpSrcW);
886
887 if (lpDestW != NULL)
888 GlobalFree((HGLOBAL)lpDestW);
889
890 return Ret;
891}
892
893/* EOF */
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
BOOL Error
Definition: chkdsk.c:66
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ARRAYSIZE(a)
Definition: cat.c:25
Definition: bufpool.h:45
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
LPWSTR Name
Definition: desk.c:124
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
BOOL WINAPI LookupAccountSidW(LPCWSTR pSystemName, PSID pSid, LPWSTR pAccountName, LPDWORD pdwAccountName, LPWSTR pDomainName, LPDWORD pdwDomainName, PSID_NAME_USE peUse)
Definition: misc.c:537
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:109
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define SetLastError(x)
Definition: compat.h:752
#define MAX_PATH
Definition: compat.h:34
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:492
DWORD WINAPI GetShortPathNameW(IN LPCWSTR lpszLongPath, OUT LPWSTR lpszShortPath, IN DWORD cchBuffer)
Definition: path.c:1851
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:164
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
static HKEY GetCurrentUserKey(HANDLE hToken)
Definition: environment.c:157
static BOOL GetUserAndDomainName(IN HANDLE hToken, OUT LPWSTR *UserName, OUT LPWSTR *DomainName)
Definition: environment.c:190
BOOL WINAPI DestroyEnvironmentBlock(IN LPVOID lpEnvironment)
Definition: environment.c:761
BOOL WINAPI ExpandEnvironmentStringsForUserW(IN HANDLE hToken, IN LPCWSTR lpSrc, OUT LPWSTR lpDest, IN DWORD dwSize)
Definition: environment.c:779
static BOOL SetUserEnvironmentVariable(PWSTR *Environment, LPWSTR lpName, LPWSTR lpValue, BOOL bExpand)
Definition: environment.c:34
BOOL WINAPI CreateEnvironmentBlock(OUT LPVOID *lpEnvironment, IN HANDLE hToken, IN BOOL bInherit)
Definition: environment.c:503
static BOOL AppendUserEnvironmentVariable(PWSTR *Environment, LPWSTR lpName, LPWSTR lpValue)
Definition: environment.c:116
static BOOL SetSystemEnvironment(PWSTR *Environment)
Definition: environment.c:394
static BOOL SetUserEnvironment(PWSTR *Environment, HKEY hKey, LPWSTR lpSubKeyName)
Definition: environment.c:271
BOOL WINAPI ExpandEnvironmentStringsForUserA(IN HANDLE hToken, IN LPCSTR lpSrc, OUT LPSTR lpDest, IN DWORD dwSize)
Definition: environment.c:830
BOOL GetUserSidStringFromToken(HANDLE hToken, PUNICODE_STRING SidString)
Definition: sid.c:102
BOOL WINAPI GetAllUsersProfileDirectoryW(_Out_opt_ LPWSTR lpProfileDir, _Inout_ LPDWORD lpcchSize)
Definition: profile.c:1315
BOOL WINAPI GetDefaultUserProfileDirectoryW(_Out_opt_ LPWSTR lpProfileDir, _Inout_ LPDWORD lpcchSize)
Definition: profile.c:1426
BOOL WINAPI GetUserProfileDirectoryW(_In_ HANDLE hToken, _Out_opt_ LPWSTR lpProfileDir, _Inout_ LPDWORD lpcchSize)
Definition: profile.c:1753
PSID WINAPI GetUserSid(HANDLE hToken)
Definition: sid.c:36
static const WCHAR Cleanup[]
Definition: register.c:80
#define L(x)
Definition: resources.c:13
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
IN PDCB IN POEM_STRING IN PUNICODE_STRING IN OUT POEM_STRING ShortName
Definition: fatprocs.h:1307
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
Status
Definition: gdiplustypes.h:24
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
enum _SID_NAME_USE SID_NAME_USE
#define LPTR
Definition: minwinbase.h:93
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:47
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
NTSYSAPI NTSTATUS NTAPI RtlSetEnvironmentVariable(_In_z_ PWSTR *Environment, _In_ PUNICODE_STRING Name, _In_ PUNICODE_STRING Value)
Definition: env.c:338
NTSYSAPI NTSTATUS NTAPI RtlCreateEnvironment(_In_ BOOLEAN Inherit, _Out_ PWSTR *Environment)
Definition: env.c:31
NTSYSAPI VOID NTAPI RtlDestroyEnvironment(_In_ PWSTR Environment)
Definition: env.c:116
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1165
NTSYSAPI NTSTATUS NTAPI RtlQueryEnvironmentVariable_U(_In_opt_ PWSTR Environment, _In_ PCUNICODE_STRING Name, _Out_ PUNICODE_STRING Value)
Definition: env.c:659
#define KEY_READ
Definition: nt_native.h:1026
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define KEY_QUERY_VALUE
Definition: nt_native.h:1019
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define REG_EXPAND_SZ
Definition: nt_native.h:1497
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
#define DPRINT
Definition: sndvol32.h:73
STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:236
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
const char * LPCSTR
Definition: typedefs.h:52
const uint16_t * LPCWSTR
Definition: typedefs.h:57
unsigned char * LPBYTE
Definition: typedefs.h:53
uint16_t * LPWSTR
Definition: typedefs.h:56
char * LPSTR
Definition: typedefs.h:51
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ LPCSTR lpName
Definition: winbase.h:2519
#define GMEM_FIXED
Definition: winbase.h:317
#define WINAPI
Definition: msvc.h:6
NTSYSAPI NTSTATUS WINAPI RtlExpandEnvironmentStrings_U(PCWSTR, const UNICODE_STRING *, UNICODE_STRING *, ULONG *)
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegQueryInfoKey
Definition: winreg.h:553
#define HKEY_USERS
Definition: winreg.h:13