ReactOS  0.4.12-dev-102-g4b7f1e0
installed.cpp
Go to the documentation of this file.
1 /*
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)
8  */
9 #include "rapps.h"
10 
11 #include "installed.h"
12 
13 #include "gui.h"
14 #include "misc.h"
15 
17 {
18  BOOL result = GetApplicationString(hKey, lpKeyName, String.GetBuffer(MAX_PATH));
19  String.ReleaseBuffer();
20  return result;
21 }
22 
23 BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR szString)
24 {
25  DWORD dwSize = MAX_PATH * sizeof(WCHAR);
26 
27  if (RegQueryValueExW(hKey,
28  lpKeyName,
29  NULL,
30  NULL,
31  (LPBYTE) szString,
32  &dwSize) == ERROR_SUCCESS)
33  {
34  return TRUE;
35  }
36 
37  StringCchCopyW(szString, MAX_PATH, L"---");
38  return FALSE;
39 }
40 
42 {
43  LPCWSTR szModify = L"ModifyPath";
44  LPCWSTR szUninstall = L"UninstallString";
47  DWORD dwType, dwSize;
48  INT ItemIndex;
49  LVITEMW Item;
50  HKEY hKey;
51  PINSTALLED_INFO ItemInfo;
52 
54  return FALSE;
55 
56  if (Index == -1)
57  {
59  if (ItemIndex == -1)
60  return FALSE;
61  }
62  else
63  {
64  ItemIndex = Index;
65  }
66 
67  ListView_GetItemText(hListView, ItemIndex, 0, szAppName, _countof(szAppName));
68  WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_REMOVE, szAppName);
69 
70  ZeroMemory(&Item, sizeof(Item));
71 
72  Item.mask = LVIF_PARAM;
73  Item.iItem = ItemIndex;
74  if (!ListView_GetItem(hListView, &Item))
75  return FALSE;
76 
77  ItemInfo = (PINSTALLED_INFO) Item.lParam;
78  hKey = ItemInfo->hSubKey;
79 
80  dwType = REG_SZ;
81  dwSize = MAX_PATH * sizeof(WCHAR);
82  if (RegQueryValueExW(hKey,
83  bModify ? szModify : szUninstall,
84  NULL,
85  &dwType,
86  (LPBYTE) szPath,
87  &dwSize) != ERROR_SUCCESS)
88  {
89  return FALSE;
90  }
91 
92  return StartProcess(szPath, TRUE);
93 }
94 
96 {
98  ATL::CStringW szInfo;
100 
101  if (!Info || !Info->hSubKey) return FALSE;
102 
103  GetApplicationString(Info->hSubKey, L"DisplayName", szText);
104  NewRichEditText(szText, CFE_BOLD);
105  InsertRichEditText(L"\n", 0);
106 
107 #define GET_INFO(a, b, c, d) \
108  if (GetApplicationString(Info->hSubKey, a, szInfo)) \
109  { \
110  szText.LoadStringW(b); \
111  InsertRichEditText(szText, c); \
112  InsertRichEditText(szInfo, d); \
113  } \
114 
115  GET_INFO(L"DisplayVersion", IDS_INFO_VERSION, CFE_BOLD, 0);
116  GET_INFO(L"Publisher", IDS_INFO_PUBLISHER, CFE_BOLD, 0);
117  GET_INFO(L"RegOwner", IDS_INFO_REGOWNER, CFE_BOLD, 0);
118  GET_INFO(L"ProductID", IDS_INFO_PRODUCTID, CFE_BOLD, 0);
120  GET_INFO(L"HelpTelephone", IDS_INFO_HELPPHONE, CFE_BOLD, 0);
121  GET_INFO(L"Readme", IDS_INFO_README, CFE_BOLD, 0);
122  GET_INFO(L"Contact", IDS_INFO_CONTACT, CFE_BOLD, 0);
123  GET_INFO(L"URLUpdateInfo", IDS_INFO_UPDATEINFO, CFE_BOLD, CFM_LINK);
124  GET_INFO(L"URLInfoAbout", IDS_INFO_INFOABOUT, CFE_BOLD, CFM_LINK);
125  GET_INFO(L"Comments", IDS_INFO_COMMENTS, CFE_BOLD, 0);
126  GET_INFO(L"InstallDate", IDS_INFO_INSTALLDATE, CFE_BOLD, 0);
127  GET_INFO(L"InstallLocation", IDS_INFO_INSTLOCATION, CFE_BOLD, 0);
128  GET_INFO(L"InstallSource", IDS_INFO_INSTALLSRC, CFE_BOLD, 0);
129  GET_INFO(L"UninstallString", IDS_INFO_UNINSTALLSTR, CFE_BOLD, 0);
130  GET_INFO(L"InstallSource", IDS_INFO_INSTALLSRC, CFE_BOLD, 0);
131  GET_INFO(L"ModifyPath", IDS_INFO_MODIFYPATH, CFE_BOLD, 0);
132 
133  return TRUE;
134 }
135 
137 {
139  WCHAR szFullName[MAX_PATH] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
140  ATL::CStringW szMsgText, szMsgTitle;
142 
144  return;
145 
146  Info = (PINSTALLED_INFO) ListViewGetlParam(Index);
147  if (!Info || !Info->hSubKey || (ItemIndex == -1)) return;
148 
149  if (!szMsgText.LoadStringW(IDS_APP_REG_REMOVE) ||
150  !szMsgTitle.LoadStringW(IDS_INFORMATION))
151  return;
152 
153  if (MessageBoxW(hMainWnd, szMsgText, szMsgTitle, MB_YESNO | MB_ICONQUESTION) == IDYES)
154  {
155  ATL::CStringW::CopyChars(szFullName,
156  MAX_PATH,
157  Info->szKeyName.GetString(),
158  MAX_PATH - wcslen(szFullName));
159 
160  if (RegDeleteKeyW(Info->hRootKey, szFullName) == ERROR_SUCCESS)
161  {
162  ListView_DeleteItem(hListView, ItemIndex);
163  return;
164  }
165 
166  if (!szMsgText.LoadStringW(IDS_UNABLE_TO_REMOVE))
167  return;
168 
170  }
171 }
172 
173 BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc)
174 {
175  DWORD dwSize = MAX_PATH, dwType, dwValue;
176  BOOL bIsSystemComponent, bIsUpdate;
177  ATL::CStringW szParentKeyName;
178  ATL::CStringW szDisplayName;
180  HKEY hKey;
181  LONG ItemIndex = 0;
182 
183  Info.hRootKey = IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
184 
185  if (RegOpenKeyW(Info.hRootKey,
186  L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
187  &hKey) != ERROR_SUCCESS)
188  {
189  return FALSE;
190  }
191 
192  while (RegEnumKeyExW(hKey, ItemIndex, Info.szKeyName.GetBuffer(MAX_PATH), &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
193  {
194  Info.szKeyName.ReleaseBuffer();
195  if (RegOpenKeyW(hKey, Info.szKeyName.GetString(), &Info.hSubKey) == ERROR_SUCCESS)
196  {
197  dwType = REG_DWORD;
198  dwSize = sizeof(DWORD);
199 
200  if (RegQueryValueExW(Info.hSubKey,
201  L"SystemComponent",
202  NULL,
203  &dwType,
204  (LPBYTE) &dwValue,
205  &dwSize) == ERROR_SUCCESS)
206  {
207  bIsSystemComponent = (dwValue == 0x1);
208  }
209  else
210  {
211  bIsSystemComponent = FALSE;
212  }
213 
214  dwType = REG_SZ;
215  dwSize = MAX_PATH * sizeof(WCHAR);
216  bIsUpdate = (RegQueryValueExW(Info.hSubKey,
217  L"ParentKeyName",
218  NULL,
219  &dwType,
220  (LPBYTE) szParentKeyName.GetBuffer(MAX_PATH),
221  &dwSize) == ERROR_SUCCESS);
222  szParentKeyName.ReleaseBuffer();
223 
224  dwType = REG_SZ;
225  dwSize = MAX_PATH * sizeof(WCHAR);
226  if (RegQueryValueExW(Info.hSubKey,
227  L"DisplayName",
228  NULL,
229  &dwType,
230  (LPBYTE) szDisplayName.GetBuffer(MAX_PATH),
231  &dwSize) == ERROR_SUCCESS)
232  {
233  szDisplayName.ReleaseBuffer();
234  if (EnumType < ENUM_ALL_INSTALLED || EnumType > ENUM_UPDATES)
235  EnumType = ENUM_ALL_INSTALLED;
236 
237  if (!bIsSystemComponent)
238  {
239  if ((EnumType == ENUM_ALL_INSTALLED) || /* All components */
240  ((EnumType == ENUM_INSTALLED_APPLICATIONS) && (!bIsUpdate)) || /* Applications only */
241  ((EnumType == ENUM_UPDATES) && (bIsUpdate))) /* Updates only */
242  {
243  if (!lpEnumProc(ItemIndex, szDisplayName, &Info))
244  break;
245  }
246  else
247  {
248  RegCloseKey(Info.hSubKey);
249  }
250  }
251  else
252  {
253  RegCloseKey(Info.hSubKey);
254  }
255  }
256  else
257  {
258  szDisplayName.ReleaseBuffer();
259  RegCloseKey(Info.hSubKey);
260  }
261  }
262 
263  dwSize = MAX_PATH;
264  ItemIndex++;
265  }
266 
267  Info.szKeyName.ReleaseBuffer();
268  RegCloseKey(hKey);
269 
270  return TRUE;
271 }
#define GET_INFO(a, b, c, d)
#define IDS_INFO_INSTALLDATE
Definition: resource.h:147
#define IDS_INFO_PUBLISHER
Definition: resource.h:133
DWORD_PTR ListViewGetlParam(INT item)
Definition: gui.cpp:1773
BOOL UninstallApplication(INT Index, BOOL bModify)
Definition: installed.cpp:41
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define IDYES
Definition: winuser.h:829
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define DWORD
Definition: msvc.h:34
VOID NewRichEditText(LPCWSTR szText, DWORD flags)
Definition: gui.cpp:1792
#define _countof(array)
Definition: fontsub.cpp:30
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define ListView_GetItemText(hwndLV, i, iSubItem_, pszText_, cchTextMax_)
Definition: commctrl.h:2654
#define IDS_INFO_INSTALLSRC
Definition: resource.h:144
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1240
#define IDS_UNABLE_TO_REMOVE
Definition: resource.h:102
#define IDS_INFO_README
Definition: resource.h:136
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define ZeroMemory
Definition: winbase.h:1635
BOOL ShowInstalledAppInfo(INT Index)
Definition: installed.cpp:95
static WCHAR String[]
Definition: stringtable.c:55
#define WCHAR
Definition: msvc.h:43
VOID RemoveAppFromRegistry(INT Index)
Definition: installed.cpp:136
int32_t INT
Definition: typedefs.h:56
BOOL StartProcess(ATL::CStringW &Path, BOOL Wait)
Definition: misc.cpp:128
struct TraceInfo Info
#define CFE_BOLD
Definition: richedit.h:406
#define IDS_INFO_COMMENTS
Definition: resource.h:142
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
#define MB_YESNO
Definition: winuser.h:811
static const WCHAR szText[]
Definition: dialog.c:139
ATL::CStringW szKeyName
Definition: installed.h:10
long LONG
Definition: pedump.c:60
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3311
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
LPARAM lParam
Definition: commctrl.h:2338
#define INT(a)
Definition: assyntax.h:463
smooth NULL
Definition: ftsmooth.c:416
#define MB_ICONQUESTION
Definition: winuser.h:783
#define ListView_DeleteItem(hwnd, i)
Definition: commctrl.h:2381
#define IDS_INFO_CONTACT
Definition: resource.h:139
#define LVNI_FOCUSED
Definition: commctrl.h:2393
#define EVENTLOG_SUCCESS
Definition: winnt_old.h:2629
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
Definition: misc.cpp:256
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
HKEY hSubKey
Definition: installed.h:9
BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, ATL::CStringW &String)
Definition: installed.cpp:16
#define MAX_PATH
Definition: compat.h:26
PCXSTR GetString() const
Definition: atlsimpstr.h:361
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDS_INFO_VERSION
Definition: resource.h:131
BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc)
Definition: installed.cpp:173
BOOL IsInstalledEnum(INT x)
Definition: defines.h:68
UINT mask
Definition: commctrl.h:2330
HWND hMainWnd
Definition: magnifier.c:33
VOID InsertRichEditText(LPCWSTR szText, DWORD flags)
Definition: gui.cpp:1797
static const WCHAR L[]
Definition: oid.c:1087
#define MB_ICONERROR
Definition: winuser.h:781
#define CFM_LINK
Definition: richedit.h:337
#define IDS_INFO_UNINSTALLSTR
Definition: resource.h:145
TCHAR szAppName[128]
Definition: solitaire.cpp:16
#define IDS_INFO_UPDATEINFO
Definition: resource.h:140
static const WCHAR szUninstall[]
Definition: registry.c:162
INSTALLED_INFO * PINSTALLED_INFO
Definition: installed.h:13
HWND hListView
Definition: gui.cpp:29
#define IDS_APP_REG_REMOVE
Definition: resource.h:100
BOOL(CALLBACK * APPENUMPROC)(INT ItemIndex, ATL::CStringW &Name, PINSTALLED_INFO Info)
Definition: installed.h:14
LPCWSTR szPath
Definition: env.c:35
#define IDS_INFO_PRODUCTID
Definition: resource.h:138
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDS_INFO_HELPPHONE
Definition: resource.h:135
static void __cdecl CopyChars(_Out_writes_to_(nDestLen, nChars) XCHAR *pchDest, _In_ size_t nDestLen, _In_reads_opt_(nChars) const XCHAR *pchSrc, _In_ int nChars)
Definition: atlsimpstr.h:423
#define MB_OK
Definition: winuser.h:784
#define IDS_INFORMATION
Definition: resource.h:101
#define MAX_STR_LEN
Definition: defines.h:33
#define ListView_GetItem(hwnd, pitem)
Definition: commctrl.h:2364
#define LVIF_PARAM
Definition: commctrl.h:2281
#define IDS_INFO_MODIFYPATH
Definition: resource.h:146
#define IDS_INFO_INSTLOCATION
Definition: resource.h:143
INT SelectedEnumType
Definition: winmain.cpp:18
#define IDS_INFO_HELPLINK
Definition: resource.h:134
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2541
HKEY hRootKey
Definition: installed.h:8
#define IDS_INFO_REGOWNER
Definition: resource.h:137
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LVM_GETNEXTITEM
Definition: commctrl.h:2403
GLuint64EXT * result
Definition: glext.h:11304
#define REG_DWORD
Definition: sdbapi.c:539
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define IDS_INFO_INFOABOUT
Definition: resource.h:141
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22