2 * Implementation of userenv.dll
4 * Copyright 2006 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_NO_STATUS
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 WINE_DEFAULT_DEBUG_CHANNEL( userenv
);
39 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
41 TRACE("%p %d %p\n", hinstDLL
, fdwReason
, lpvReserved
);
45 case DLL_WINE_PREATTACH
:
46 return FALSE
; /* prefer native version */
47 case DLL_PROCESS_ATTACH
:
48 DisableThreadLibraryCalls(hinstDLL
);
54 static BOOL
get_reg_value(WCHAR
*env
, HKEY hkey
, const WCHAR
*name
, WCHAR
*val
, DWORD size
)
56 DWORD type
, res_size
=0;
58 if (RegQueryValueExW(hkey
, name
, 0, &type
, NULL
, &res_size
) != ERROR_SUCCESS
)
66 return RegQueryValueExW(hkey
, name
, 0, NULL
, (BYTE
*)val
, &size
) == ERROR_SUCCESS
;
68 else if (type
== REG_EXPAND_SZ
)
70 UNICODE_STRING us_buf
, us_expanded
;
71 WCHAR
*buf
= HeapAlloc(GetProcessHeap(), 0, res_size
);
75 if (RegQueryValueExW(hkey
, name
, 0, NULL
, (BYTE
*)buf
, &res_size
) != ERROR_SUCCESS
)
77 HeapFree(GetProcessHeap(), 0, buf
);
81 RtlInitUnicodeString(&us_buf
, buf
);
82 us_expanded
.Buffer
= val
;
83 us_expanded
.MaximumLength
= size
;
84 if (RtlExpandEnvironmentStrings_U(env
, &us_buf
, &us_expanded
, &size
) != STATUS_SUCCESS
)
86 HeapFree(GetProcessHeap(), 0, buf
);
90 HeapFree(GetProcessHeap(), 0, buf
);
97 static void set_registry_variables(WCHAR
**env
, HKEY hkey
, DWORD type
, BOOL set_path
)
99 static const WCHAR SystemRootW
[] = {'S','y','s','t','e','m','R','o','o','t',0};
100 static const WCHAR SystemDriveW
[] = {'S','y','s','t','e','m','D','r','i','v','e',0};
101 static const WCHAR PATHW
[] = {'P','A','T','H'};
103 UNICODE_STRING us_name
, us_value
;
104 WCHAR name
[1024], value
[1024];
105 DWORD ret
, index
, size
;
107 for (index
= 0; ; index
++)
109 size
= ARRAY_SIZE(name
);
110 ret
= RegEnumValueW(hkey
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
);
111 if (ret
!= ERROR_SUCCESS
)
114 if (!memicmpW(name
, SystemRootW
, ARRAY_SIZE(SystemRootW
)))
116 if (!memicmpW(name
, SystemDriveW
, ARRAY_SIZE(SystemDriveW
)))
119 RtlInitUnicodeString(&us_name
, name
);
120 us_value
.Buffer
= value
;
121 us_value
.MaximumLength
= sizeof(value
);
122 if (!memicmpW(name
, PATHW
, ARRAY_SIZE(PATHW
)) &&
123 !RtlQueryEnvironmentVariable_U(*env
, &us_name
, &us_value
))
128 size
= strlenW(value
)+1;
129 if (!get_reg_value(*env
, hkey
, name
, value
+size
,
130 sizeof(value
)-size
*sizeof(WCHAR
)))
134 RtlInitUnicodeString(&us_value
, value
);
135 RtlSetEnvironmentVariable(env
, &us_name
, &us_value
);
139 if (!get_reg_value(*env
, hkey
, name
, value
, sizeof(value
)))
145 RtlInitUnicodeString(&us_value
, value
);
146 RtlSetEnvironmentVariable(env
, &us_name
, &us_value
);
150 static void set_wow64_environment(WCHAR
**env
)
152 static const WCHAR versionW
[] = {'S','o','f','t','w','a','r','e','\\',
153 'M','i','c','r','o','s','o','f','t','\\',
154 'W','i','n','d','o','w','s','\\',
155 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
156 static const WCHAR progdirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
157 static const WCHAR progdir86W
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
158 static const WCHAR progfilesW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s',0};
159 static const WCHAR progw6432W
[] = {'P','r','o','g','r','a','m','W','6','4','3','2',0};
160 static const WCHAR commondirW
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',0};
161 static const WCHAR commondir86W
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
162 static const WCHAR commonfilesW
[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','F','i','l','e','s',0};
163 static const WCHAR commonw6432W
[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','W','6','4','3','2',0};
165 UNICODE_STRING nameW
, valueW
;
168 BOOL is_win64
= (sizeof(void *) > sizeof(int));
171 IsWow64Process( GetCurrentProcess(), &is_wow64
);
173 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, versionW
, 0,
174 KEY_READ
|KEY_WOW64_64KEY
, &hkey
))
177 /* set the ProgramFiles variables */
179 if (get_reg_value(*env
, hkey
, progdirW
, buf
, sizeof(buf
)))
181 if (is_win64
|| is_wow64
)
183 RtlInitUnicodeString(&nameW
, progw6432W
);
184 RtlInitUnicodeString(&valueW
, buf
);
185 RtlSetEnvironmentVariable(env
, &nameW
, &valueW
);
187 if (is_win64
|| !is_wow64
)
189 RtlInitUnicodeString(&nameW
, progfilesW
);
190 RtlInitUnicodeString(&valueW
, buf
);
191 RtlSetEnvironmentVariable(env
, &nameW
, &valueW
);
194 if (is_wow64
&& get_reg_value(*env
, hkey
, progdir86W
, buf
, sizeof(buf
)))
196 RtlInitUnicodeString(&nameW
, progfilesW
);
197 RtlInitUnicodeString(&valueW
, buf
);
198 RtlSetEnvironmentVariable(env
, &nameW
, &valueW
);
201 /* set the CommonProgramFiles variables */
203 if (get_reg_value(*env
, hkey
, commondirW
, buf
, sizeof(buf
)))
205 if (is_win64
|| is_wow64
)
207 RtlInitUnicodeString(&nameW
, commonw6432W
);
208 RtlInitUnicodeString(&valueW
, buf
);
209 RtlSetEnvironmentVariable(env
, &nameW
, &valueW
);
211 if (is_win64
|| !is_wow64
)
213 RtlInitUnicodeString(&nameW
, commonfilesW
);
214 RtlInitUnicodeString(&valueW
, buf
);
215 RtlSetEnvironmentVariable(env
, &nameW
, &valueW
);
218 if (is_wow64
&& get_reg_value(*env
, hkey
, commondir86W
, buf
, sizeof(buf
)))
220 RtlInitUnicodeString(&nameW
, commonfilesW
);
221 RtlInitUnicodeString(&valueW
, buf
);
222 RtlSetEnvironmentVariable(env
, &nameW
, &valueW
);
228 BOOL WINAPI
CreateEnvironmentBlock( LPVOID
* lpEnvironment
,
229 HANDLE hToken
, BOOL bInherit
)
231 static const WCHAR env_keyW
[] = {'S','y','s','t','e','m','\\',
232 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
233 'C','o','n','t','r','o','l','\\',
234 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
235 'E','n','v','i','r','o','n','m','e','n','t',0};
236 static const WCHAR profile_keyW
[] = {'S','o','f','t','w','a','r','e','\\',
237 'M','i','c','r','o','s','o','f','t','\\',
238 'W','i','n','d','o','w','s',' ','N','T','\\',
239 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
240 'P','r','o','f','i','l','e','L','i','s','t',0};
241 static const WCHAR envW
[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
242 static const WCHAR volatile_envW
[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0};
243 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
245 static const WCHAR SystemRootW
[] = {'S','y','s','t','e','m','R','o','o','t',0};
246 static const WCHAR SystemDriveW
[] = {'S','y','s','t','e','m','D','r','i','v','e',0};
247 static const WCHAR PublicW
[] = {'P','u','b','l','i','c',0};
248 static const WCHAR ALLUSERSPROFILEW
[] = {'A','L','L','U','S','E','R','S','P','R','O','F','I','L','E',0};
249 static const WCHAR USERNAMEW
[] = {'U','S','E','R','N','A','M','E',0};
250 static const WCHAR USERPROFILEW
[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
251 static const WCHAR DefaultW
[] = {'D','e','f','a','u','l','t',0};
252 static const WCHAR COMPUTERNAMEW
[] = {'C','O','M','P','U','T','E','R','N','A','M','E',0};
254 WCHAR
*env
, buf
[UNICODE_STRING_MAX_CHARS
], profiles_dir
[MAX_PATH
];
255 UNICODE_STRING us_name
, us_val
;
259 TRACE("%p %p %d\n", lpEnvironment
, hToken
, bInherit
);
264 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, env_keyW
, 0, KEY_READ
, &hkey
) != ERROR_SUCCESS
)
267 if (RtlCreateEnvironment(bInherit
, &env
) != STATUS_SUCCESS
)
273 if (!GetEnvironmentVariableW(SystemRootW
, buf
, UNICODE_STRING_MAX_CHARS
))
275 if (!get_reg_value(env
, hkey
, SystemRootW
, buf
, UNICODE_STRING_MAX_CHARS
))
278 WARN("SystemRoot variable not set\n");
281 RtlInitUnicodeString(&us_name
, SystemRootW
);
282 RtlInitUnicodeString(&us_val
, buf
);
283 RtlSetEnvironmentVariable(&env
, &us_name
, &us_val
);
285 if (!GetEnvironmentVariableW(SystemDriveW
, buf
, UNICODE_STRING_MAX_CHARS
))
287 if (!get_reg_value(env
, hkey
, SystemRootW
, buf
, UNICODE_STRING_MAX_CHARS
))
290 WARN("SystemDrive variable not set\n");
293 RtlInitUnicodeString(&us_name
, SystemDriveW
);
294 RtlInitUnicodeString(&us_val
, buf
);
295 RtlSetEnvironmentVariable(&env
, &us_name
, &us_val
);
297 set_registry_variables(&env
, hkey
, REG_SZ
, !bInherit
);
298 set_registry_variables(&env
, hkey
, REG_EXPAND_SZ
, !bInherit
);
300 if (RegOpenKeyExW(hkey
, envW
, 0, KEY_READ
, &hsubkey
) == ERROR_SUCCESS
)
302 set_registry_variables(&env
, hsubkey
, REG_SZ
, !bInherit
);
303 set_registry_variables(&env
, hsubkey
, REG_EXPAND_SZ
, !bInherit
);
304 RegCloseKey(hsubkey
);
307 if (RegOpenKeyExW(hkey
, volatile_envW
, 0, KEY_READ
, &hsubkey
) == ERROR_SUCCESS
)
309 set_registry_variables(&env
, hsubkey
, REG_SZ
, !bInherit
);
310 set_registry_variables(&env
, hsubkey
, REG_EXPAND_SZ
, !bInherit
);
311 RegCloseKey(hsubkey
);
315 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, profile_keyW
, 0, KEY_READ
, &hkey
) == ERROR_SUCCESS
)
317 if (get_reg_value(env
, hkey
, ProfilesDirectoryW
, profiles_dir
, MAX_PATH
-sizeof(WCHAR
)))
319 len
= strlenW(profiles_dir
);
320 if (profiles_dir
[len
-1] != '\\')
322 profiles_dir
[len
++] = '\\';
323 profiles_dir
[len
] = '\0';
326 if (get_reg_value(env
, hkey
, PublicW
, buf
, UNICODE_STRING_MAX_CHARS
))
328 RtlInitUnicodeString(&us_name
, ALLUSERSPROFILEW
);
329 RtlInitUnicodeString(&us_val
, buf
);
330 RtlSetEnvironmentVariable(&env
, &us_name
, &us_val
);
341 len
= ARRAY_SIZE(buf
);
342 if (GetComputerNameW(buf
, &len
))
344 RtlInitUnicodeString(&us_name
, COMPUTERNAMEW
);
345 RtlInitUnicodeString(&us_val
, buf
);
346 RtlSetEnvironmentVariable(&env
, &us_name
, &us_val
);
349 set_wow64_environment(&env
);
355 len
= strlenW(profiles_dir
);
356 if (len
*sizeof(WCHAR
)+sizeof(DefaultW
) < sizeof(buf
))
358 memcpy(buf
, profiles_dir
, len
*sizeof(WCHAR
));
359 memcpy(buf
+len
, DefaultW
, sizeof(DefaultW
));
360 RtlInitUnicodeString(&us_name
, USERPROFILEW
);
361 RtlInitUnicodeString(&us_val
, buf
);
362 RtlSetEnvironmentVariable(&env
, &us_name
, &us_val
);
367 memcpy(buf
+1, DefaultW
, sizeof(DefaultW
));
371 TOKEN_USER
*token_user
= NULL
;
376 if (GetTokenInformation(hToken
, TokenUser
, NULL
, 0, &len
) ||
377 GetLastError()!=ERROR_INSUFFICIENT_BUFFER
||
378 !(token_user
= HeapAlloc(GetProcessHeap(), 0, len
)) ||
379 !GetTokenInformation(hToken
, TokenUser
, token_user
, len
, &len
) ||
380 !ConvertSidToStringSidW(token_user
->User
.Sid
, &sidW
))
382 HeapFree(GetProcessHeap(), 0, token_user
);
383 RtlDestroyEnvironment(env
);
387 len
= strlenW(profiles_dir
);
388 memcpy(buf
, profiles_dir
, len
*sizeof(WCHAR
));
390 size
= UNICODE_STRING_MAX_CHARS
-len
;
391 if (LookupAccountSidW(NULL
, token_user
->User
.Sid
,
392 buf
+len
, &size
, NULL
, &tmp
, &use
))
394 RtlInitUnicodeString(&us_name
, USERNAMEW
);
395 RtlInitUnicodeString(&us_val
, buf
+len
);
396 RtlSetEnvironmentVariable(&env
, &us_name
, &us_val
);
400 RtlInitUnicodeString(&us_name
, USERPROFILEW
);
401 RtlInitUnicodeString(&us_val
, buf
);
402 RtlSetEnvironmentVariable(&env
, &us_name
, &us_val
);
406 HeapFree(GetProcessHeap(), 0, token_user
);
411 if (RegOpenKeyExW(HKEY_USERS
, buf
, 0, KEY_READ
, &hkey
) == ERROR_SUCCESS
)
413 if (RegOpenKeyExW(hkey
, envW
, 0, KEY_READ
, &hsubkey
) == ERROR_SUCCESS
)
415 set_registry_variables(&env
, hsubkey
, REG_SZ
, !bInherit
);
416 set_registry_variables(&env
, hsubkey
, REG_EXPAND_SZ
, !bInherit
);
417 RegCloseKey(hsubkey
);
420 if (RegOpenKeyExW(hkey
, volatile_envW
, 0, KEY_READ
, &hsubkey
) == ERROR_SUCCESS
)
422 set_registry_variables(&env
, hsubkey
, REG_SZ
, !bInherit
);
423 set_registry_variables(&env
, hsubkey
, REG_EXPAND_SZ
, !bInherit
);
424 RegCloseKey(hsubkey
);
429 *lpEnvironment
= env
;
433 BOOL WINAPI
DestroyEnvironmentBlock(LPVOID lpEnvironment
)
437 TRACE("%p\n", lpEnvironment
);
438 r
= RtlDestroyEnvironment(lpEnvironment
);
439 if (r
== STATUS_SUCCESS
)
444 BOOL WINAPI
ExpandEnvironmentStringsForUserA( HANDLE hToken
, LPCSTR lpSrc
,
445 LPSTR lpDest
, DWORD dwSize
)
449 TRACE("%p %s %p %d\n", hToken
, debugstr_a(lpSrc
), lpDest
, dwSize
);
451 ret
= ExpandEnvironmentStringsA( lpSrc
, lpDest
, dwSize
);
452 TRACE("<- %s\n", debugstr_a(lpDest
));
456 BOOL WINAPI
ExpandEnvironmentStringsForUserW( HANDLE hToken
, LPCWSTR lpSrc
,
457 LPWSTR lpDest
, DWORD dwSize
)
461 TRACE("%p %s %p %d\n", hToken
, debugstr_w(lpSrc
), lpDest
, dwSize
);
463 ret
= ExpandEnvironmentStringsW( lpSrc
, lpDest
, dwSize
);
464 TRACE("<- %s\n", debugstr_w(lpDest
));
468 BOOL WINAPI
GetDefaultUserProfileDirectoryA( LPSTR lpProfileDir
, LPDWORD lpcchSize
)
470 FIXME("%p %p\n", lpProfileDir
, lpcchSize
);
474 BOOL WINAPI
GetDefaultUserProfileDirectoryW( LPWSTR lpProfileDir
, LPDWORD lpcchSize
)
476 FIXME("%p %p\n", lpProfileDir
, lpcchSize
);
480 BOOL WINAPI
GetUserProfileDirectoryA( HANDLE hToken
, LPSTR lpProfileDir
,
486 TRACE( "%p %p %p\n", hToken
, lpProfileDir
, lpcchSize
);
488 if (!lpProfileDir
|| !lpcchSize
)
490 SetLastError( ERROR_INVALID_PARAMETER
);
493 if (!(dirW
= HeapAlloc( GetProcessHeap(), 0, *lpcchSize
* sizeof(WCHAR
) )))
496 if ((ret
= GetUserProfileDirectoryW( hToken
, dirW
, lpcchSize
)))
497 WideCharToMultiByte( CP_ACP
, 0, dirW
, *lpcchSize
, lpProfileDir
, *lpcchSize
, NULL
, NULL
);
499 HeapFree( GetProcessHeap(), 0, dirW
);
503 BOOL WINAPI
GetUserProfileDirectoryW( HANDLE hToken
, LPWSTR lpProfileDir
,
506 static const WCHAR slashW
[] = {'\\',0};
508 WCHAR
*userW
= NULL
, *dirW
= NULL
;
509 DWORD len
, dir_len
, domain_len
;
513 TRACE( "%p %p %p\n", hToken
, lpProfileDir
, lpcchSize
);
517 SetLastError( ERROR_INVALID_PARAMETER
);
522 GetTokenInformation( hToken
, TokenUser
, NULL
, 0, &len
);
523 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
) return FALSE
;
524 if (!(t
= HeapAlloc( GetProcessHeap(), 0, len
))) return FALSE
;
525 if (!GetTokenInformation( hToken
, TokenUser
, t
, len
, &len
)) goto done
;
527 len
= domain_len
= 0;
528 LookupAccountSidW( NULL
, t
->User
.Sid
, NULL
, &len
, NULL
, &domain_len
, NULL
);
529 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
) goto done
;
530 if (!(userW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) goto done
;
531 if (!LookupAccountSidW( NULL
, t
->User
.Sid
, userW
, &len
, NULL
, &domain_len
, &use
)) goto done
;
534 GetProfilesDirectoryW( NULL
, &dir_len
);
535 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
) goto done
;
536 if (!(dirW
= HeapAlloc( GetProcessHeap(), 0, (dir_len
+ 1) * sizeof(WCHAR
) ))) goto done
;
537 if (!GetProfilesDirectoryW( dirW
, &dir_len
)) goto done
;
540 if (*lpcchSize
< len
)
542 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
546 strcpyW( lpProfileDir
, dirW
);
547 strcatW( lpProfileDir
, slashW
);
548 strcatW( lpProfileDir
, userW
);
553 HeapFree( GetProcessHeap(), 0, t
);
554 HeapFree( GetProcessHeap(), 0, userW
);
555 HeapFree( GetProcessHeap(), 0, dirW
);
559 static const char ProfileListA
[] = "Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList";
561 BOOL WINAPI
GetProfilesDirectoryA( LPSTR lpProfilesDir
, LPDWORD lpcchSize
)
563 static const char ProfilesDirectory
[] = "ProfilesDirectory";
567 DWORD len
= 0, expanded_len
;
568 LPSTR unexpanded_profiles_dir
= NULL
;
570 TRACE("%p %p\n", lpProfilesDir
, lpcchSize
);
572 if (!lpProfilesDir
|| !lpcchSize
)
574 SetLastError(ERROR_INVALID_PARAMETER
);
578 l
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, ProfileListA
, 0, KEY_READ
, &key
);
584 l
= RegQueryValueExA(key
, ProfilesDirectory
, NULL
, NULL
, NULL
, &len
);
590 unexpanded_profiles_dir
= HeapAlloc(GetProcessHeap(), 0, len
);
591 if (!unexpanded_profiles_dir
)
593 SetLastError(ERROR_OUTOFMEMORY
);
596 l
= RegQueryValueExA(key
, ProfilesDirectory
, NULL
, NULL
,
597 (BYTE
*)unexpanded_profiles_dir
, &len
);
603 expanded_len
= ExpandEnvironmentStringsA(unexpanded_profiles_dir
, NULL
, 0);
604 /* The returned length doesn't include the NULL terminator. */
605 if (*lpcchSize
< expanded_len
- 1)
607 *lpcchSize
= expanded_len
- 1;
608 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
611 *lpcchSize
= expanded_len
- 1;
612 /* The return value is also the expected length. */
613 ret
= ExpandEnvironmentStringsA(unexpanded_profiles_dir
, lpProfilesDir
,
616 HeapFree(GetProcessHeap(), 0, unexpanded_profiles_dir
);
621 static const WCHAR ProfileListW
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','P','r','o','f','i','l','e','L','i','s','t',0};
623 BOOL WINAPI
GetProfilesDirectoryW( LPWSTR lpProfilesDir
, LPDWORD lpcchSize
)
625 static const WCHAR ProfilesDirectory
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
629 DWORD len
= 0, expanded_len
;
630 LPWSTR unexpanded_profiles_dir
= NULL
;
632 TRACE("%p %p\n", lpProfilesDir
, lpcchSize
);
636 SetLastError(ERROR_INVALID_PARAMETER
);
640 l
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, ProfileListW
, 0, KEY_READ
, &key
);
646 l
= RegQueryValueExW(key
, ProfilesDirectory
, NULL
, NULL
, NULL
, &len
);
652 unexpanded_profiles_dir
= HeapAlloc(GetProcessHeap(), 0, len
);
653 if (!unexpanded_profiles_dir
)
655 SetLastError(ERROR_OUTOFMEMORY
);
658 l
= RegQueryValueExW(key
, ProfilesDirectory
, NULL
, NULL
,
659 (BYTE
*)unexpanded_profiles_dir
, &len
);
665 expanded_len
= ExpandEnvironmentStringsW(unexpanded_profiles_dir
, NULL
, 0);
666 /* The returned length doesn't include the NULL terminator. */
667 if (*lpcchSize
< expanded_len
- 1 || !lpProfilesDir
)
669 *lpcchSize
= expanded_len
- 1;
670 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
673 *lpcchSize
= expanded_len
- 1;
674 /* The return value is also the expected length. */
675 ret
= ExpandEnvironmentStringsW(unexpanded_profiles_dir
, lpProfilesDir
,
678 HeapFree(GetProcessHeap(), 0, unexpanded_profiles_dir
);
683 BOOL WINAPI
GetAllUsersProfileDirectoryA( LPSTR lpProfileDir
, LPDWORD lpcchSize
)
685 FIXME("%p %p\n", lpProfileDir
, lpcchSize
);
689 BOOL WINAPI
GetAllUsersProfileDirectoryW( LPWSTR lpProfileDir
, LPDWORD lpcchSize
)
691 FIXME("%p %p\n", lpProfileDir
, lpcchSize
);
695 BOOL WINAPI
GetProfileType( DWORD
*pdwFlags
)
697 FIXME("%p\n", pdwFlags
);
702 BOOL WINAPI
LoadUserProfileA( HANDLE hToken
, LPPROFILEINFOA lpProfileInfo
)
704 FIXME("%p %p\n", hToken
, lpProfileInfo
);
705 lpProfileInfo
->hProfile
= HKEY_CURRENT_USER
;
709 BOOL WINAPI
LoadUserProfileW( HANDLE hToken
, LPPROFILEINFOW lpProfileInfo
)
711 FIXME("%p %p\n", hToken
, lpProfileInfo
);
712 lpProfileInfo
->hProfile
= HKEY_CURRENT_USER
;
716 BOOL WINAPI
RegisterGPNotification( HANDLE event
, BOOL machine
)
718 FIXME("%p %d\n", event
, machine
);
722 BOOL WINAPI
UnregisterGPNotification( HANDLE event
)
724 FIXME("%p\n", event
);
728 BOOL WINAPI
UnloadUserProfile( HANDLE hToken
, HANDLE hProfile
)
730 FIXME("(%p, %p): stub\n", hToken
, hProfile
);
734 HANDLE WINAPI
EnterCriticalPolicySection(BOOL bMachine
)
736 FIXME("(%x)\n", bMachine
);
737 SetLastError(ERROR_ACCESS_DENIED
);
741 BOOL WINAPI
LeaveCriticalPolicySection(HANDLE hSection
)
743 FIXME("(%p)\n", hSection
);
747 DWORD WINAPI
GetAppliedGPOListW(DWORD dwFlags
, LPCWSTR pMachineName
, PSID pSidUser
, GUID
*pGuidExtension
,
748 PGROUP_POLICY_OBJECTW
*ppGPOList
)
750 FIXME("(%x %s %p %s %p)\n", dwFlags
, debugstr_w(pMachineName
), pSidUser
, debugstr_guid(pGuidExtension
), ppGPOList
);
751 return ERROR_ACCESS_DENIED
;
754 /******************************************************************************
760 * int csidl [in] well-known directory location to create link in
761 * LPCSTR lnk_dir [in] directory (relative to directory specified by csidl) to create link in
762 * LPCSTR lnk_filename [in] filename of the link file without .lnk extension
763 * LPCSTR lnk_target [in] file/directory pointed to by link
764 * LPCSTR lnk_iconfile [in] link icon resource filename
765 * DWORD lnk_iconid [in] link icon resource id in file referred by lnk_iconfile
766 * LPCSTR work_directory [in] link target's work directory
767 * WORD hotkey [in] link hotkey (virtual key id)
768 * DWORD win_state [in] initial window size (SW_SHOWMAXIMIZED to start maximized,
769 * SW_SHOWMINNOACTIVE to start minimized, everything else is default state)
770 * LPCSTR comment [in] comment - link's comment
771 * LPCSTR loc_filename_resfile [in] resource file which holds localized filename for this link file
772 * DWORD loc_filename_resid [in] resource id for this link file's localized filename
775 * TRUE: Link file was successfully created
776 * FALSE: Link file was not created
778 BOOL WINAPI
USERENV_138( int csidl
, LPCSTR lnk_dir
, LPCSTR lnk_filename
,
779 LPCSTR lnk_target
, LPCSTR lnk_iconfile
, DWORD lnk_iconid
,
780 LPCSTR work_directory
, WORD hotkey
, DWORD win_state
, LPCSTR comment
,
781 LPCSTR loc_filename_resfile
, DWORD loc_filename_resid
)
783 FIXME("(%d,%s,%s,%s,%s,%d,%s,0x%x,%d,%s,%s,%d) - stub\n", csidl
, debugstr_a(lnk_dir
),
784 debugstr_a(lnk_filename
), debugstr_a(lnk_target
), debugstr_a(lnk_iconfile
),
785 lnk_iconid
, debugstr_a(work_directory
), hotkey
, win_state
,
786 debugstr_a(comment
), debugstr_a(loc_filename_resfile
), loc_filename_resid
);