static VOID
AddUserProfile(
_In_ HWND hwndListView,
- _In_ LPTSTR lpProfileSid,
+ _In_ PSID pProfileSid,
_In_ PSID pMySid,
_In_ HKEY hProfileKey)
{
DWORD dwAccountNameSize, dwDomainNameSize;
DWORD dwProfileData, dwSize, dwType, dwState = 0;
PWSTR ptr;
- PSID pSid = NULL;
INT nId, iItem;
LV_ITEM lvi;
- if (!ConvertStringSidToSid(lpProfileSid,
- &pSid))
- return;
-
dwAccountNameSize = ARRAYSIZE(szAccountName);
dwDomainNameSize = ARRAYSIZE(szDomainName);
if (!LookupAccountSidW(NULL,
- pSid,
+ pProfileSid,
szAccountName,
&dwAccountNameSize,
szDomainName,
{
/* Show only the user accounts */
if (Use != SidTypeUser)
- goto done;
+ return;
if (szAccountName[0] == UNICODE_NULL)
{
0,
dwProfileData);
if (pProfileData == NULL)
- goto done;
+ return;
- pProfileData->bMyProfile = EqualSid(pMySid, pSid);
+ pProfileData->bMyProfile = EqualSid(pMySid, pProfileSid);
pProfileData->dwState = dwState;
ptr = (PWSTR)((ULONG_PTR)pProfileData + sizeof(PROFILEDATA));
LoadStringW(hApplet, nId, szAccountName, ARRAYSIZE(szAccountName));
ListView_SetItemText(hwndListView, iItem, 2, szAccountName);
-
-done:
- if (pSid != NULL)
- LocalFree(pSid);
}
if (Item.lParam != 0)
{
bMyProfile = ((PPROFILEDATA)Item.lParam)->bMyProfile;
- if (/*IsUserAnAdmin() &&*/ !bMyProfile)
+ if (!bMyProfile)
{
EnableWindow(GetDlgItem(hwndDlg, IDC_USERPROFILE_DELETE), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_USERPROFILE_COPY), TRUE);
static VOID
AddUserProfiles(
_In_ HWND hwndDlg,
- _In_ HWND hwndListView)
+ _In_ HWND hwndListView,
+ _In_ BOOL bAdmin)
{
HKEY hKeyUserProfiles = INVALID_HANDLE_VALUE;
HKEY hProfileKey;
DWORD dwSize;
HANDLE hToken = NULL;
PTOKEN_USER pTokenUser = NULL;
+ PSID pProfileSid;
+ PWSTR pszProfileSid;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
return;
&hKeyUserProfiles))
goto done;
- for (dwIndex = 0; ; dwIndex++)
+ if (bAdmin)
{
- dwSidLength = ARRAYSIZE(szProfileSid);
- if (RegEnumKeyExW(hKeyUserProfiles,
- dwIndex,
- szProfileSid,
- &dwSidLength,
- NULL,
- NULL,
- NULL,
- &ftLastWrite))
- break;
+ for (dwIndex = 0; ; dwIndex++)
+ {
+ dwSidLength = ARRAYSIZE(szProfileSid);
+ if (RegEnumKeyExW(hKeyUserProfiles,
+ dwIndex,
+ szProfileSid,
+ &dwSidLength,
+ NULL,
+ NULL,
+ NULL,
+ &ftLastWrite))
+ break;
+
+ if (RegOpenKeyExW(hKeyUserProfiles,
+ szProfileSid,
+ 0,
+ KEY_READ,
+ &hProfileKey) == ERROR_SUCCESS)
+ {
+ if (ConvertStringSidToSid(szProfileSid, &pProfileSid))
+ {
+ AddUserProfile(hwndListView, pProfileSid, pTokenUser->User.Sid, hProfileKey);
+ LocalFree(pProfileSid);
+ }
- if (RegOpenKeyExW(hKeyUserProfiles,
- szProfileSid,
- 0,
- KEY_READ,
- &hProfileKey) == ERROR_SUCCESS)
+ RegCloseKey(hProfileKey);
+ }
+ }
+ }
+ else
+ {
+ if (ConvertSidToStringSidW(pTokenUser->User.Sid, &pszProfileSid))
{
- AddUserProfile(hwndListView, szProfileSid, pTokenUser->User.Sid, hProfileKey);
- RegCloseKey(hProfileKey);
+ if (RegOpenKeyExW(hKeyUserProfiles,
+ pszProfileSid,
+ 0,
+ KEY_READ,
+ &hProfileKey) == ERROR_SUCCESS)
+ {
+ AddUserProfile(hwndListView, pTokenUser->User.Sid, pTokenUser->User.Sid, hProfileKey);
+ RegCloseKey(hProfileKey);
+ }
+
+ LocalFree(pszProfileSid);
}
}
if (ListView_GetItemCount(hwndListView) != 0)
- ListView_SetItemState(hwndListView, 0, LVIS_SELECTED, LVIS_SELECTED);
+ ListView_SetItemState(hwndListView, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
UpdateButtonState(hwndDlg, hwndListView);
static VOID
OnInitUserProfileDialog(HWND hwndDlg)
{
+ BOOL bAdmin;
+
+ bAdmin = IsUserAdmin();
+
/* Initialize the list view control */
SetListViewColumns(GetDlgItem(hwndDlg, IDC_USERPROFILE_LIST));
- AddUserProfiles(hwndDlg, GetDlgItem(hwndDlg, IDC_USERPROFILE_LIST));
+ /* Hide the delete and copy buttons for non-admins */
+ ShowWindow(GetDlgItem(hwndDlg, IDC_USERPROFILE_DELETE), bAdmin ? SW_SHOW : SW_HIDE);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_USERPROFILE_COPY), bAdmin ? SW_SHOW : SW_HIDE);
+
+ /* Add the profiles to the list view */
+ AddUserProfiles(hwndDlg, GetDlgItem(hwndDlg, IDC_USERPROFILE_LIST), bAdmin);
}