2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * FILE: base/applications/rapps/installed.cpp
5 * PURPOSE: Functions for working with installed applications
6 * COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
7 * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
11 #include "installed.h"
16 BOOL
INSTALLED_INFO::GetApplicationString(LPCWSTR lpKeyName
, ATL::CStringW
& String
)
18 BOOL result
= ::GetApplicationString(hSubKey
, lpKeyName
, String
.GetBuffer(MAX_PATH
));
19 String
.ReleaseBuffer();
23 BOOL
GetApplicationString(HKEY hKey
, LPCWSTR lpKeyName
, LPWSTR szString
)
25 DWORD dwSize
= MAX_PATH
* sizeof(WCHAR
);
27 if (RegQueryValueExW(hKey
,
32 &dwSize
) == ERROR_SUCCESS
)
37 StringCchCopyW(szString
, MAX_PATH
, L
"---");
41 BOOL
UninstallApplication(INT Index
, BOOL bModify
)
43 LPCWSTR szModify
= L
"ModifyPath";
44 LPCWSTR szUninstall
= L
"UninstallString";
45 WCHAR szPath
[MAX_PATH
];
46 WCHAR szAppName
[MAX_STR_LEN
];
51 PINSTALLED_INFO ItemInfo
;
53 if (!IsInstalledEnum(SelectedEnumType
))
58 ItemIndex
= (INT
) SendMessageW(hListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
67 ListView_GetItemText(hListView
, ItemIndex
, 0, szAppName
, _countof(szAppName
));
68 WriteLogMessage(EVENTLOG_SUCCESS
, MSG_SUCCESS_REMOVE
, szAppName
);
70 ZeroMemory(&Item
, sizeof(Item
));
72 Item
.mask
= LVIF_PARAM
;
73 Item
.iItem
= ItemIndex
;
74 if (!ListView_GetItem(hListView
, &Item
))
77 ItemInfo
= (PINSTALLED_INFO
) Item
.lParam
;
78 hKey
= ItemInfo
->hSubKey
;
81 dwSize
= MAX_PATH
* sizeof(WCHAR
);
82 if (RegQueryValueExW(hKey
,
83 bModify
? szModify
: szUninstall
,
87 &dwSize
) != ERROR_SUCCESS
)
92 return StartProcess(szPath
, TRUE
);
95 VOID
RemoveAppFromRegistry(INT Index
)
98 WCHAR szFullName
[MAX_PATH
] = L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
99 ATL::CStringW szMsgText
, szMsgTitle
;
100 INT ItemIndex
= SendMessageW(hListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
102 if (!IsInstalledEnum(SelectedEnumType
))
105 Info
= (PINSTALLED_INFO
) ListViewGetlParam(Index
);
106 if (!Info
|| !Info
->hSubKey
|| (ItemIndex
== -1)) return;
108 if (!szMsgText
.LoadStringW(IDS_APP_REG_REMOVE
) ||
109 !szMsgTitle
.LoadStringW(IDS_INFORMATION
))
112 if (MessageBoxW(hMainWnd
, szMsgText
, szMsgTitle
, MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
114 ATL::CStringW::CopyChars(szFullName
,
116 Info
->szKeyName
.GetString(),
117 MAX_PATH
- wcslen(szFullName
));
119 if (RegDeleteKeyW(Info
->hRootKey
, szFullName
) == ERROR_SUCCESS
)
121 ListView_DeleteItem(hListView
, ItemIndex
);
125 if (!szMsgText
.LoadStringW(IDS_UNABLE_TO_REMOVE
))
128 MessageBoxW(hMainWnd
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
132 BOOL
EnumInstalledApplications(INT EnumType
, BOOL IsUserKey
, APPENUMPROC lpEnumProc
, PVOID param
)
134 DWORD dwSize
= MAX_PATH
, dwType
, dwValue
;
135 BOOL bIsSystemComponent
, bIsUpdate
;
136 ATL::CStringW szParentKeyName
;
137 ATL::CStringW szDisplayName
;
142 Info
.hRootKey
= IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
;
144 if (RegOpenKeyW(Info
.hRootKey
,
145 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
146 &hKey
) != ERROR_SUCCESS
)
151 while (RegEnumKeyExW(hKey
, ItemIndex
, Info
.szKeyName
.GetBuffer(MAX_PATH
), &dwSize
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
153 Info
.szKeyName
.ReleaseBuffer();
154 if (RegOpenKeyW(hKey
, Info
.szKeyName
.GetString(), &Info
.hSubKey
) == ERROR_SUCCESS
)
157 dwSize
= sizeof(DWORD
);
159 if (RegQueryValueExW(Info
.hSubKey
,
164 &dwSize
) == ERROR_SUCCESS
)
166 bIsSystemComponent
= (dwValue
== 0x1);
170 bIsSystemComponent
= FALSE
;
174 dwSize
= MAX_PATH
* sizeof(WCHAR
);
175 bIsUpdate
= (RegQueryValueExW(Info
.hSubKey
,
179 (LPBYTE
) szParentKeyName
.GetBuffer(MAX_PATH
),
180 &dwSize
) == ERROR_SUCCESS
);
181 szParentKeyName
.ReleaseBuffer();
184 dwSize
= MAX_PATH
* sizeof(WCHAR
);
185 if (RegQueryValueExW(Info
.hSubKey
,
189 (LPBYTE
) szDisplayName
.GetBuffer(MAX_PATH
),
190 &dwSize
) == ERROR_SUCCESS
)
192 szDisplayName
.ReleaseBuffer();
193 if (EnumType
< ENUM_ALL_INSTALLED
|| EnumType
> ENUM_UPDATES
)
194 EnumType
= ENUM_ALL_INSTALLED
;
196 if (!bIsSystemComponent
)
198 if ((EnumType
== ENUM_ALL_INSTALLED
) || /* All components */
199 ((EnumType
== ENUM_INSTALLED_APPLICATIONS
) && (!bIsUpdate
)) || /* Applications only */
200 ((EnumType
== ENUM_UPDATES
) && (bIsUpdate
))) /* Updates only */
202 if (!lpEnumProc(ItemIndex
, szDisplayName
, &Info
, param
))
207 RegCloseKey(Info
.hSubKey
);
212 RegCloseKey(Info
.hSubKey
);
217 szDisplayName
.ReleaseBuffer();
218 RegCloseKey(Info
.hSubKey
);
226 Info
.szKeyName
.ReleaseBuffer();