4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS system libraries
21 * FILE: lib/userenv/profile.c
22 * PURPOSE: User profile code
23 * PROGRAMMERS: Eric Kohl
33 /* FUNCTIONS ***************************************************************/
36 AppendSystemPostfix(LPWSTR lpName
,
39 WCHAR szSystemRoot
[MAX_PATH
];
43 /* Build profile name postfix */
44 if (!ExpandEnvironmentStringsW(L
"%SystemRoot%",
48 DPRINT1("Error: %lu\n", GetLastError());
52 _wcsupr(szSystemRoot
);
54 /* Get name postfix */
55 szSystemRoot
[2] = L
'.';
56 lpszPostfix
= &szSystemRoot
[2];
57 lpszPtr
= lpszPostfix
;
58 while (*lpszPtr
!= (WCHAR
)0)
60 if (*lpszPtr
== L
'\\')
65 if (wcslen(lpName
) + wcslen(lpszPostfix
) + 1 >= dwMaxLength
)
67 DPRINT1("Error: buffer overflow\n");
68 SetLastError(ERROR_BUFFER_OVERFLOW
);
72 wcscat(lpName
, lpszPostfix
);
80 CreateUserProfileA(PSID Sid
,
83 UNICODE_STRING UserName
;
87 Status
= RtlCreateUnicodeStringFromAsciiz(&UserName
,
89 if (!NT_SUCCESS(Status
))
91 SetLastError(RtlNtStatusToDosError(Status
));
95 bResult
= CreateUserProfileW(Sid
, UserName
.Buffer
);
97 RtlFreeUnicodeString(&UserName
);
105 AcquireRemoveRestorePrivilege(IN BOOL bAcquire
)
109 PTOKEN_PRIVILEGES TokenPriv
;
112 DPRINT("AcquireRemoveRestorePrivilege(%d)\n", bAcquire
);
114 Process
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, GetCurrentProcessId());
117 DPRINT1("OpenProcess() failed with error %lu\n", GetLastError());
120 bRet
= OpenProcessToken(Process
, TOKEN_ADJUST_PRIVILEGES
, &Token
);
121 CloseHandle(Process
);
124 DPRINT1("OpenProcessToken() failed with error %lu\n", GetLastError());
127 TokenPriv
= HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(TOKEN_PRIVILEGES
, Privileges
) + sizeof(LUID_AND_ATTRIBUTES
));
130 DPRINT1("Failed to allocate mem for token privileges\n");
132 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
135 TokenPriv
->PrivilegeCount
= 1;
136 TokenPriv
->Privileges
[0].Attributes
= bAcquire
? SE_PRIVILEGE_ENABLED
: 0;
137 if (!LookupPrivilegeValue(NULL
, SE_RESTORE_NAME
, &TokenPriv
->Privileges
[0].Luid
))
139 DPRINT1("LookupPrivilegeValue() failed with error %lu\n", GetLastError());
140 HeapFree(GetProcessHeap(), 0, TokenPriv
);
144 bRet
= AdjustTokenPrivileges(
151 HeapFree(GetProcessHeap(), 0, TokenPriv
);
156 DPRINT1("AdjustTokenPrivileges() failed with error %lu\n", GetLastError());
166 CreateUserProfileW(PSID Sid
,
169 WCHAR szRawProfilesPath
[MAX_PATH
];
170 WCHAR szProfilesPath
[MAX_PATH
];
171 WCHAR szUserProfilePath
[MAX_PATH
];
172 WCHAR szDefaultUserPath
[MAX_PATH
];
173 WCHAR szUserProfileName
[MAX_PATH
];
174 WCHAR szBuffer
[MAX_PATH
];
182 DPRINT("CreateUserProfileW() called\n");
184 Error
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
185 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
189 if (Error
!= ERROR_SUCCESS
)
191 DPRINT1("Error: %lu\n", Error
);
192 SetLastError((DWORD
)Error
);
196 /* Get profiles path */
197 dwLength
= MAX_PATH
* sizeof(WCHAR
);
198 Error
= RegQueryValueExW(hKey
,
199 L
"ProfilesDirectory",
202 (LPBYTE
)szRawProfilesPath
,
204 if (Error
!= ERROR_SUCCESS
)
206 DPRINT1("Error: %lu\n", Error
);
208 SetLastError((DWORD
)Error
);
213 if (!ExpandEnvironmentStringsW(szRawProfilesPath
,
217 DPRINT1("Error: %lu\n", GetLastError());
222 /* create the profiles directory if it does not yet exist */
223 if (!CreateDirectoryW(szProfilesPath
, NULL
))
225 if (GetLastError() != ERROR_ALREADY_EXISTS
)
227 DPRINT1("Error: %lu\n", GetLastError());
232 /* Get default user path */
233 dwLength
= MAX_PATH
* sizeof(WCHAR
);
234 Error
= RegQueryValueExW(hKey
,
235 L
"DefaultUserProfile",
240 if (Error
!= ERROR_SUCCESS
)
242 DPRINT1("Error: %lu\n", Error
);
244 SetLastError((DWORD
)Error
);
250 wcscpy(szUserProfileName
, lpUserName
);
252 wcscpy(szUserProfilePath
, szProfilesPath
);
253 wcscat(szUserProfilePath
, L
"\\");
254 wcscat(szUserProfilePath
, szUserProfileName
);
256 wcscpy(szDefaultUserPath
, szProfilesPath
);
257 wcscat(szDefaultUserPath
, L
"\\");
258 wcscat(szDefaultUserPath
, szBuffer
);
260 /* Create user profile directory */
261 if (!CreateDirectoryW(szUserProfilePath
, NULL
))
263 if (GetLastError() != ERROR_ALREADY_EXISTS
)
265 DPRINT1("Error: %lu\n", GetLastError());
269 for (i
= 0; i
< 1000; i
++)
271 swprintf(szUserProfileName
, L
"%s.%03u", lpUserName
, i
);
273 wcscpy(szUserProfilePath
, szProfilesPath
);
274 wcscat(szUserProfilePath
, L
"\\");
275 wcscat(szUserProfilePath
, szUserProfileName
);
277 if (CreateDirectoryW(szUserProfilePath
, NULL
))
280 if (GetLastError() != ERROR_ALREADY_EXISTS
)
282 DPRINT1("Error: %lu\n", GetLastError());
288 /* Copy default user directory */
289 if (!CopyDirectory(szUserProfilePath
, szDefaultUserPath
))
291 DPRINT1("Error: %lu\n", GetLastError());
295 /* Add profile to profile list */
296 if (!ConvertSidToStringSidW(Sid
,
299 DPRINT1("Error: %lu\n", GetLastError());
304 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
305 wcscat(szBuffer
, SidString
);
307 /* Create user profile key */
308 Error
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
312 REG_OPTION_NON_VOLATILE
,
317 if (Error
!= ERROR_SUCCESS
)
319 DPRINT1("Error: %lu\n", Error
);
320 LocalFree((HLOCAL
)SidString
);
321 SetLastError((DWORD
)Error
);
325 /* Create non-expanded user profile path */
326 wcscpy(szBuffer
, szRawProfilesPath
);
327 wcscat(szBuffer
, L
"\\");
328 wcscat(szBuffer
, szUserProfileName
);
330 /* Set 'ProfileImagePath' value (non-expanded) */
331 Error
= RegSetValueExW(hKey
,
336 (wcslen (szBuffer
) + 1) * sizeof(WCHAR
));
337 if (Error
!= ERROR_SUCCESS
)
339 DPRINT1("Error: %lu\n", Error
);
340 LocalFree((HLOCAL
)SidString
);
342 SetLastError((DWORD
)Error
);
346 /* Set 'Sid' value */
347 Error
= RegSetValueExW(hKey
,
353 if (Error
!= ERROR_SUCCESS
)
355 DPRINT1("Error: %lu\n", Error
);
356 LocalFree((HLOCAL
)SidString
);
358 SetLastError((DWORD
)Error
);
364 /* Create user hive name */
365 wcscpy(szBuffer
, szUserProfilePath
);
366 wcscat(szBuffer
, L
"\\ntuser.dat");
368 /* Acquire restore privilege */
369 if (!AcquireRemoveRestorePrivilege(TRUE
))
371 DPRINT1("Error: %lu\n", Error
);
372 LocalFree((HLOCAL
)SidString
);
376 /* Create new user hive */
377 Error
= RegLoadKeyW(HKEY_USERS
,
380 AcquireRemoveRestorePrivilege(FALSE
);
381 if (Error
!= ERROR_SUCCESS
)
383 DPRINT1("Error: %lu\n", Error
);
384 LocalFree((HLOCAL
)SidString
);
385 SetLastError((DWORD
)Error
);
389 /* Initialize user hive */
390 if (!CreateUserHive(SidString
, szUserProfilePath
))
392 DPRINT1("Error: %lu\n", GetLastError());
393 LocalFree((HLOCAL
)SidString
);
397 RegUnLoadKeyW(HKEY_USERS
, SidString
);
399 LocalFree((HLOCAL
)SidString
);
401 DPRINT("CreateUserProfileW() done\n");
409 GetAllUsersProfileDirectoryA(LPSTR lpProfileDir
,
415 lpBuffer
= GlobalAlloc(GMEM_FIXED
,
416 *lpcchSize
* sizeof(WCHAR
));
417 if (lpBuffer
== NULL
)
420 bResult
= GetAllUsersProfileDirectoryW(lpBuffer
,
424 WideCharToMultiByte(CP_ACP
,
434 GlobalFree(lpBuffer
);
442 GetAllUsersProfileDirectoryW(LPWSTR lpProfileDir
,
445 WCHAR szProfilePath
[MAX_PATH
];
446 WCHAR szBuffer
[MAX_PATH
];
451 Error
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
452 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
456 if (Error
!= ERROR_SUCCESS
)
458 DPRINT1("Error: %lu\n", Error
);
459 SetLastError((DWORD
)Error
);
463 /* Get profiles path */
464 dwLength
= sizeof(szBuffer
);
465 Error
= RegQueryValueExW(hKey
,
466 L
"ProfilesDirectory",
471 if (Error
!= ERROR_SUCCESS
)
473 DPRINT1("Error: %lu\n", Error
);
475 SetLastError((DWORD
)Error
);
480 if (!ExpandEnvironmentStringsW(szBuffer
,
484 DPRINT1("Error: %lu\n", GetLastError());
489 /* Get 'AllUsersProfile' name */
490 dwLength
= sizeof(szBuffer
);
491 Error
= RegQueryValueExW(hKey
,
497 if (Error
!= ERROR_SUCCESS
)
499 DPRINT1("Error: %lu\n", Error
);
501 SetLastError((DWORD
)Error
);
507 wcscat(szProfilePath
, L
"\\");
508 wcscat(szProfilePath
, szBuffer
);
510 dwLength
= wcslen(szProfilePath
) + 1;
511 if (lpProfileDir
!= NULL
)
513 if (*lpcchSize
< dwLength
)
515 *lpcchSize
= dwLength
;
516 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
520 wcscpy(lpProfileDir
, szProfilePath
);
523 *lpcchSize
= dwLength
;
531 GetDefaultUserProfileDirectoryA(LPSTR lpProfileDir
,
537 lpBuffer
= GlobalAlloc(GMEM_FIXED
,
538 *lpcchSize
* sizeof(WCHAR
));
539 if (lpBuffer
== NULL
)
542 bResult
= GetDefaultUserProfileDirectoryW(lpBuffer
,
546 WideCharToMultiByte(CP_ACP
,
556 GlobalFree(lpBuffer
);
564 GetDefaultUserProfileDirectoryW(LPWSTR lpProfileDir
,
567 WCHAR szProfilePath
[MAX_PATH
];
568 WCHAR szBuffer
[MAX_PATH
];
573 Error
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
574 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
578 if (Error
!= ERROR_SUCCESS
)
580 DPRINT1("Error: %lu\n", Error
);
581 SetLastError((DWORD
)Error
);
585 /* Get profiles path */
586 dwLength
= sizeof(szBuffer
);
587 Error
= RegQueryValueExW(hKey
,
588 L
"ProfilesDirectory",
593 if (Error
!= ERROR_SUCCESS
)
595 DPRINT1("Error: %lu\n", Error
);
597 SetLastError((DWORD
)Error
);
602 if (!ExpandEnvironmentStringsW(szBuffer
,
606 DPRINT1("Error: %lu\n", GetLastError());
611 /* Get 'DefaultUserProfile' name */
612 dwLength
= sizeof(szBuffer
);
613 Error
= RegQueryValueExW(hKey
,
614 L
"DefaultUserProfile",
619 if (Error
!= ERROR_SUCCESS
)
621 DPRINT1("Error: %lu\n", Error
);
623 SetLastError((DWORD
)Error
);
629 wcscat(szProfilePath
, L
"\\");
630 wcscat(szProfilePath
, szBuffer
);
632 dwLength
= wcslen(szProfilePath
) + 1;
633 if (lpProfileDir
!= NULL
)
635 if (*lpcchSize
< dwLength
)
637 *lpcchSize
= dwLength
;
638 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
642 wcscpy(lpProfileDir
, szProfilePath
);
645 *lpcchSize
= dwLength
;
653 GetProfilesDirectoryA(LPSTR lpProfileDir
,
659 lpBuffer
= GlobalAlloc(GMEM_FIXED
,
660 *lpcchSize
* sizeof(WCHAR
));
661 if (lpBuffer
== NULL
)
664 bResult
= GetProfilesDirectoryW(lpBuffer
,
668 WideCharToMultiByte(CP_ACP
,
678 GlobalFree(lpBuffer
);
686 GetProfilesDirectoryW(LPWSTR lpProfilesDir
,
689 WCHAR szProfilesPath
[MAX_PATH
];
690 WCHAR szBuffer
[MAX_PATH
];
695 Error
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
696 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
700 if (Error
!= ERROR_SUCCESS
)
702 DPRINT1("Error: %lu\n", Error
);
703 SetLastError((DWORD
)Error
);
707 /* Get profiles path */
708 dwLength
= sizeof(szBuffer
);
709 Error
= RegQueryValueExW(hKey
,
710 L
"ProfilesDirectory",
715 if (Error
!= ERROR_SUCCESS
)
717 DPRINT1("Error: %lu\n", Error
);
719 SetLastError((DWORD
)Error
);
726 if (!ExpandEnvironmentStringsW(szBuffer
,
730 DPRINT1("Error: %lu\n", GetLastError());
734 dwLength
= wcslen (szProfilesPath
) + 1;
735 if (lpProfilesDir
!= NULL
)
737 if (*lpcchSize
< dwLength
)
739 *lpcchSize
= dwLength
;
740 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
744 wcscpy(lpProfilesDir
, szProfilesPath
);
747 *lpcchSize
= dwLength
;
755 GetUserProfileDirectoryA(HANDLE hToken
,
762 lpBuffer
= GlobalAlloc(GMEM_FIXED
,
763 *lpcchSize
* sizeof(WCHAR
));
764 if (lpBuffer
== NULL
)
767 bResult
= GetUserProfileDirectoryW(hToken
,
772 WideCharToMultiByte(CP_ACP
,
782 GlobalFree(lpBuffer
);
790 GetUserProfileDirectoryW(HANDLE hToken
,
794 UNICODE_STRING SidString
;
795 WCHAR szKeyName
[MAX_PATH
];
796 WCHAR szRawImagePath
[MAX_PATH
];
797 WCHAR szImagePath
[MAX_PATH
];
802 if (!GetUserSidFromToken(hToken
,
805 DPRINT1("GetUserSidFromToken() failed\n");
809 DPRINT("SidString: '%wZ'\n", &SidString
);
812 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
816 RtlFreeUnicodeString(&SidString
);
818 DPRINT("KeyName: '%S'\n", szKeyName
);
820 Error
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
825 if (Error
!= ERROR_SUCCESS
)
827 DPRINT1("Error: %lu\n", Error
);
828 SetLastError((DWORD
)Error
);
832 dwLength
= sizeof(szRawImagePath
);
833 Error
= RegQueryValueExW(hKey
,
837 (LPBYTE
)szRawImagePath
,
839 if (Error
!= ERROR_SUCCESS
)
841 DPRINT1("Error: %lu\n", Error
);
843 SetLastError((DWORD
)Error
);
849 DPRINT("RawImagePath: '%S'\n", szRawImagePath
);
852 if (!ExpandEnvironmentStringsW(szRawImagePath
,
856 DPRINT1 ("Error: %lu\n", GetLastError());
860 DPRINT("ImagePath: '%S'\n", szImagePath
);
862 dwLength
= wcslen (szImagePath
) + 1;
863 if (*lpcchSize
< dwLength
)
865 *lpcchSize
= dwLength
;
866 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
870 *lpcchSize
= dwLength
;
871 wcscpy(lpProfileDir
, szImagePath
);
879 CheckForLoadedProfile(HANDLE hToken
)
881 UNICODE_STRING SidString
;
884 DPRINT("CheckForLoadedProfile() called\n");
886 if (!GetUserSidFromToken(hToken
,
889 DPRINT1("GetUserSidFromToken() failed\n");
893 if (RegOpenKeyExW(HKEY_USERS
,
899 DPRINT("Profile not loaded\n");
900 RtlFreeUnicodeString(&SidString
);
906 RtlFreeUnicodeString(&SidString
);
908 DPRINT("Profile already loaded\n");
916 LoadUserProfileA(HANDLE hToken
,
917 LPPROFILEINFOA lpProfileInfo
)
919 DPRINT ("LoadUserProfileA() not implemented\n");
926 LoadUserProfileW(IN HANDLE hToken
,
927 IN OUT LPPROFILEINFOW lpProfileInfo
)
929 WCHAR szUserHivePath
[MAX_PATH
];
930 LPWSTR UserName
= NULL
, Domain
= NULL
;
931 DWORD UserNameLength
= 0, DomainLength
= 0;
932 PTOKEN_USER UserSid
= NULL
;
933 SID_NAME_USE AccountType
;
934 UNICODE_STRING SidString
= { 0, 0, NULL
};
937 DWORD dwLength
= sizeof(szUserHivePath
) / sizeof(szUserHivePath
[0]);
939 DPRINT("LoadUserProfileW() called\n");
941 /* Check profile info */
942 if (!lpProfileInfo
|| (lpProfileInfo
->dwSize
!= sizeof(PROFILEINFOW
)) ||
943 (lpProfileInfo
->lpUserName
== NULL
) || (lpProfileInfo
->lpUserName
[0] == 0))
945 SetLastError(ERROR_INVALID_PARAMETER
);
949 /* Don't load a profile twice */
950 if (CheckForLoadedProfile(hToken
))
952 DPRINT ("Profile already loaded\n");
953 lpProfileInfo
->hProfile
= NULL
;
957 if (lpProfileInfo
->lpProfilePath
)
959 wcscpy(szUserHivePath
, lpProfileInfo
->lpProfilePath
);
963 /* FIXME: check if MS Windows allows lpProfileInfo->lpProfilePath to be NULL */
964 if (!GetProfilesDirectoryW(szUserHivePath
, &dwLength
))
966 DPRINT1("GetProfilesDirectoryW() failed (error %ld)\n", GetLastError());
971 /* Create user hive name */
972 wcscat(szUserHivePath
, L
"\\");
973 wcscat(szUserHivePath
, lpProfileInfo
->lpUserName
);
974 wcscat(szUserHivePath
, L
"\\ntuser.dat");
975 DPRINT("szUserHivePath: %S\n", szUserHivePath
);
977 /* Create user profile directory if needed */
978 if (GetFileAttributesW(szUserHivePath
) == INVALID_FILE_ATTRIBUTES
)
981 if (GetTokenInformation(hToken
, TokenUser
, NULL
, 0, &dwLength
) ||
982 GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
984 DPRINT1 ("GetTokenInformation() failed\n");
988 UserSid
= (PTOKEN_USER
)HeapAlloc(GetProcessHeap(), 0, dwLength
);
991 DPRINT1("HeapAlloc() failed\n");
992 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
996 if (!GetTokenInformation(hToken
, TokenUser
, UserSid
, dwLength
, &dwLength
))
998 DPRINT1("GetTokenInformation() failed\n");
1005 if (UserNameLength
> 0)
1007 HeapFree(GetProcessHeap(), 0, UserName
);
1008 UserName
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, UserNameLength
* sizeof(WCHAR
));
1011 DPRINT1("HeapAlloc() failed\n");
1012 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1016 if (DomainLength
> 0)
1018 HeapFree(GetProcessHeap(), 0, Domain
);
1019 Domain
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, DomainLength
* sizeof(WCHAR
));
1022 DPRINT1("HeapAlloc() failed\n");
1023 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1027 ret
= LookupAccountSidW(NULL
,
1034 } while (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
);
1038 DPRINT1("LookupAccountSidW() failed\n");
1042 /* Create profile */
1043 /* FIXME: ignore Domain? */
1044 DPRINT("UserName %S, Domain %S\n", UserName
, Domain
);
1045 ret
= CreateUserProfileW(UserSid
->User
.Sid
, UserName
);
1048 DPRINT1("CreateUserProfileW() failed\n");
1053 /* Get user SID string */
1054 ret
= GetUserSidFromToken(hToken
, &SidString
);
1057 DPRINT1("GetUserSidFromToken() failed\n");
1062 /* Acquire restore privilege */
1063 if (!AcquireRemoveRestorePrivilege(TRUE
))
1065 DPRINT1("AcquireRemoveRestorePrivilege() failed (Error %ld)\n", GetLastError());
1069 /* Load user registry hive */
1070 Error
= RegLoadKeyW(HKEY_USERS
,
1073 AcquireRemoveRestorePrivilege(FALSE
);
1074 if (Error
!= ERROR_SUCCESS
)
1076 DPRINT1("RegLoadKeyW() failed (Error %ld)\n", Error
);
1077 SetLastError((DWORD
)Error
);
1081 /* Open future HKEY_CURRENT_USER */
1082 Error
= RegOpenKeyExW(HKEY_USERS
,
1086 (PHKEY
)&lpProfileInfo
->hProfile
);
1087 if (Error
!= ERROR_SUCCESS
)
1089 DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error
);
1090 SetLastError((DWORD
)Error
);
1097 HeapFree(GetProcessHeap(), 0, UserSid
);
1098 HeapFree(GetProcessHeap(), 0, UserName
);
1099 HeapFree(GetProcessHeap(), 0, Domain
);
1100 RtlFreeUnicodeString(&SidString
);
1102 DPRINT("LoadUserProfileW() done\n");
1109 UnloadUserProfile(HANDLE hToken
,
1112 UNICODE_STRING SidString
;
1115 DPRINT("UnloadUserProfile() called\n");
1117 if (hProfile
== NULL
)
1119 DPRINT1("Invalide profile handle\n");
1120 SetLastError(ERROR_INVALID_PARAMETER
);
1124 RegCloseKey(hProfile
);
1126 if (!GetUserSidFromToken(hToken
,
1129 DPRINT1("GetUserSidFromToken() failed\n");
1133 DPRINT("SidString: '%wZ'\n", &SidString
);
1135 /* Acquire restore privilege */
1136 if (!AcquireRemoveRestorePrivilege(TRUE
))
1138 DPRINT1("AcquireRemoveRestorePrivilege() failed (Error %ld)\n", GetLastError());
1139 RtlFreeUnicodeString(&SidString
);
1143 /* Unload the hive */
1144 Error
= RegUnLoadKeyW(HKEY_USERS
,
1147 /* Remove restore privilege */
1148 AcquireRemoveRestorePrivilege(FALSE
);
1150 if (Error
!= ERROR_SUCCESS
)
1152 DPRINT1("RegUnLoadKeyW() failed (Error %ld)\n", Error
);
1153 RtlFreeUnicodeString(&SidString
);
1154 SetLastError((DWORD
)Error
);
1158 RtlFreeUnicodeString(&SidString
);
1160 DPRINT("UnloadUserProfile() done\n");
1167 DeleteProfileW(LPCWSTR lpSidString
,
1168 LPCWSTR lpProfilePath
,
1169 LPCWSTR lpComputerName
)
1171 DPRINT1("DeleteProfileW() not implemented!\n");
1177 DeleteProfileA(LPCSTR lpSidString
,
1178 LPCSTR lpProfilePath
,
1179 LPCSTR lpComputerName
)
1181 DPRINT1("DeleteProfileA() not implemented!\n");