2 * PROJECT: ReactOS System Control Panel Applet
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/sysdm/userprofile.c
5 * PURPOSE: Computer settings for networking
6 * COPYRIGHT: Copyright Thomas Weidenmueller <w3seek@reactos.org>
7 * Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
15 typedef struct _PROFILEDATA
19 } PROFILEDATA
, *PPROFILEDATA
;
23 SetListViewColumns(HWND hwndListView
)
29 GetClientRect(hwndListView
, &rect
);
31 SendMessage(hwndListView
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
33 memset(&column
, 0x00, sizeof(column
));
34 column
.mask
= LVCF_FMT
| LVCF_WIDTH
| LVCF_SUBITEM
| LVCF_TEXT
;
35 column
.fmt
= LVCFMT_LEFT
;
36 column
.cx
= (INT
)((rect
.right
- rect
.left
) * 0.40);
38 LoadString(hApplet
, IDS_USERPROFILE_NAME
, szStr
, ARRAYSIZE(szStr
));
39 column
.pszText
= szStr
;
40 (void)ListView_InsertColumn(hwndListView
, 0, &column
);
42 column
.fmt
= LVCFMT_RIGHT
;
43 column
.cx
= (INT
)((rect
.right
- rect
.left
) * 0.15);
45 LoadString(hApplet
, IDS_USERPROFILE_SIZE
, szStr
, ARRAYSIZE(szStr
));
46 column
.pszText
= szStr
;
47 (void)ListView_InsertColumn(hwndListView
, 1, &column
);
49 column
.fmt
= LVCFMT_LEFT
;
50 column
.cx
= (INT
)((rect
.right
- rect
.left
) * 0.15);
52 LoadString(hApplet
, IDS_USERPROFILE_TYPE
, szStr
, ARRAYSIZE(szStr
));
53 column
.pszText
= szStr
;
54 (void)ListView_InsertColumn(hwndListView
, 2, &column
);
56 column
.fmt
= LVCFMT_LEFT
;
57 column
.cx
= (INT
)((rect
.right
- rect
.left
) * 0.15);
59 LoadString(hApplet
, IDS_USERPROFILE_STATUS
, szStr
, ARRAYSIZE(szStr
));
60 column
.pszText
= szStr
;
61 (void)ListView_InsertColumn(hwndListView
, 3, &column
);
63 column
.fmt
= LVCFMT_LEFT
;
64 column
.cx
= (INT
)((rect
.right
- rect
.left
) * 0.15) - GetSystemMetrics(SM_CYHSCROLL
);
66 LoadString(hApplet
, IDS_USERPROFILE_MODIFIED
, szStr
, ARRAYSIZE(szStr
));
67 column
.pszText
= szStr
;
68 (void)ListView_InsertColumn(hwndListView
, 4, &column
);
74 _In_ HWND hwndListView
,
75 _In_ LPTSTR lpProfileSid
,
78 PPROFILEDATA pProfileData
= NULL
;
79 PWSTR pszAccountName
= NULL
;
80 PWSTR pszDomainName
= NULL
;
82 DWORD dwAccountNameSize
, dwDomainNameSize
;
88 if (!ConvertStringSidToSid(lpProfileSid
,
92 dwAccountNameSize
= 0;
94 LookupAccountSidW(NULL
,
102 pszDomainName
= HeapAlloc(GetProcessHeap(),
104 dwDomainNameSize
* sizeof(WCHAR
));
105 if (pszDomainName
== NULL
)
108 pszAccountName
= HeapAlloc(GetProcessHeap(),
110 dwAccountNameSize
* sizeof(WCHAR
));
111 if (pszAccountName
== NULL
)
114 if (!LookupAccountSidW(NULL
,
123 /* Show only the user accounts */
124 if (Use
!= SidTypeUser
)
127 dwProfileData
= sizeof(PROFILEDATA
) +
128 ((wcslen(pszDomainName
) + wcslen(pszAccountName
) + 2) * sizeof(WCHAR
));
129 pProfileData
= HeapAlloc(GetProcessHeap(),
132 if (pProfileData
== NULL
)
135 pProfileData
->bMyProfile
= EqualSid(pMySid
, pSid
);
137 ptr
= (PWSTR
)((ULONG_PTR
)pProfileData
+ sizeof(PROFILEDATA
));
138 pProfileData
->pszFullName
= ptr
;
140 wsprintf(pProfileData
->pszFullName
, L
"%s\\%s", pszDomainName
, pszAccountName
);
142 memset(&lvi
, 0x00, sizeof(lvi
));
143 lvi
.mask
= LVIF_TEXT
| LVIF_STATE
| LVIF_PARAM
;
144 lvi
.pszText
= pProfileData
->pszFullName
;
146 lvi
.lParam
= (LPARAM
)pProfileData
;
147 ListView_InsertItem(hwndListView
, &lvi
);
150 if (pszDomainName
!= NULL
)
151 HeapFree(GetProcessHeap(), 0, pszDomainName
);
153 if (pszAccountName
!= NULL
)
154 HeapFree(GetProcessHeap(), 0, pszAccountName
);
162 AddUserProfiles(HWND hwndListView
)
164 HKEY hKeyUserProfiles
= INVALID_HANDLE_VALUE
;
166 WCHAR szProfileSid
[64];
168 FILETIME ftLastWrite
;
170 HANDLE hToken
= NULL
;
171 PTOKEN_USER pTokenUser
= NULL
;
173 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
176 GetTokenInformation(hToken
, TokenUser
, NULL
, 0, &dwSize
);
180 pTokenUser
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
181 if (pTokenUser
== NULL
)
184 if (!GetTokenInformation(hToken
, TokenUser
, pTokenUser
, dwSize
, &dwSize
))
187 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
188 L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
194 for (dwIndex
= 0; ; dwIndex
++)
196 dwSidLength
= ARRAYSIZE(szProfileSid
);
197 if (RegEnumKeyExW(hKeyUserProfiles
,
207 AddUserProfile(hwndListView
, szProfileSid
, pTokenUser
->User
.Sid
);
210 if (ListView_GetItemCount(hwndListView
) != 0)
211 ListView_SetItemState(hwndListView
, 0, LVIS_SELECTED
, LVIS_SELECTED
);
214 if (hKeyUserProfiles
!= INVALID_HANDLE_VALUE
)
215 RegCloseKey(hKeyUserProfiles
);
217 if (pTokenUser
!= NULL
)
218 HeapFree(GetProcessHeap(), 0, pTokenUser
);
226 OnInitUserProfileDialog(HWND hwndDlg
)
228 /* Initialize the list view control */
229 SetListViewColumns(GetDlgItem(hwndDlg
, IDC_USERPROFILE_LIST
));
231 AddUserProfiles(GetDlgItem(hwndDlg
, IDC_USERPROFILE_LIST
));
233 /* Disable the "Delete" and "Copy To" buttons if the user is not an admin */
234 if (!IsUserAnAdmin())
236 EnableWindow(GetDlgItem(hwndDlg
, IDC_USERPROFILE_DELETE
), FALSE
);
237 EnableWindow(GetDlgItem(hwndDlg
, IDC_USERPROFILE_COPY
), FALSE
);
251 hwndList
= GetDlgItem(hwndDlg
, IDC_USERPROFILE_LIST
);
253 nItems
= ListView_GetItemCount(hwndList
);
254 for (i
= 0; i
< nItems
; i
++)
258 if (ListView_GetItem(hwndList
, &Item
))
260 if (Item
.lParam
!= 0)
261 HeapFree(GetProcessHeap(), 0, (PVOID
)Item
.lParam
);
273 if (nmhdr
->idFrom
== IDC_USERACCOUNT_LINK
&& nmhdr
->code
== NM_CLICK
)
275 ShellExecuteW(hwndDlg
, NULL
, L
"usrmgr.cpl", NULL
, NULL
, 0);
277 else if (nmhdr
->idFrom
== IDC_USERPROFILE_LIST
&& nmhdr
->code
== LVN_ITEMCHANGED
)
279 if (ListView_GetSelectedCount(nmhdr
->hwndFrom
) == 0)
281 EnableWindow(GetDlgItem(hwndDlg
, IDC_USERPROFILE_CHANGE
), FALSE
);
282 EnableWindow(GetDlgItem(hwndDlg
, IDC_USERPROFILE_DELETE
), FALSE
);
283 EnableWindow(GetDlgItem(hwndDlg
, IDC_USERPROFILE_COPY
), FALSE
);
289 BOOL bMyProfile
= FALSE
;
291 iSelected
= ListView_GetNextItem(nmhdr
->hwndFrom
, -1, LVNI_SELECTED
);
294 Item
.iItem
= iSelected
;
296 if (ListView_GetItem(nmhdr
->hwndFrom
, &Item
))
298 if (Item
.lParam
!= 0)
300 bMyProfile
= ((PPROFILEDATA
)Item
.lParam
)->bMyProfile
;
305 EnableWindow(GetDlgItem(hwndDlg
, IDC_USERPROFILE_CHANGE
), TRUE
);
306 if (IsUserAnAdmin() && !bMyProfile
)
308 EnableWindow(GetDlgItem(hwndDlg
, IDC_USERPROFILE_DELETE
), TRUE
);
309 EnableWindow(GetDlgItem(hwndDlg
, IDC_USERPROFILE_COPY
), TRUE
);
316 /* Property page dialog callback */
318 UserProfileDlgProc(HWND hwndDlg
,
326 OnInitUserProfileDialog(hwndDlg
);
334 switch (LOWORD(wParam
))
342 case IDC_USERPROFILE_DELETE
:
348 OnNotify(hwndDlg
, (NMHDR
*)lParam
);