ReactOS  0.4.14-dev-52-g6116262
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 "misc.h"
14 
16 {
17  BOOL result = ::GetApplicationString(hSubKey, lpKeyName, String.GetBuffer(MAX_PATH));
18  String.ReleaseBuffer();
19  return result;
20 }
21 
22 BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR szString)
23 {
24  DWORD dwSize = MAX_PATH * sizeof(WCHAR);
25 
26  if (RegQueryValueExW(hKey,
27  lpKeyName,
28  NULL,
29  NULL,
30  (LPBYTE) szString,
31  &dwSize) == ERROR_SUCCESS)
32  {
33  return TRUE;
34  }
35 
36  StringCchCopyW(szString, MAX_PATH, L"---");
37  return FALSE;
38 }
39 
41 {
42  LPCWSTR szModify = L"ModifyPath";
43  LPCWSTR szUninstall = L"UninstallString";
44  DWORD dwType, dwSize;
46 
47  dwType = REG_SZ;
48  dwSize = MAX_PATH * sizeof(WCHAR);
49  if (RegQueryValueExW(ItemInfo->hSubKey,
50  bModify ? szModify : szUninstall,
51  NULL,
52  &dwType,
53  (LPBYTE) szPath,
54  &dwSize) != ERROR_SUCCESS)
55  {
56  return FALSE;
57  }
58 
59  return StartProcess(szPath, TRUE);
60 }
61 
62 BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc, PVOID param)
63 {
64  DWORD dwSize = MAX_PATH, dwType, dwValue;
65  BOOL bIsSystemComponent, bIsUpdate;
66  ATL::CStringW szParentKeyName;
67  ATL::CStringW szDisplayName;
69  HKEY hKey;
70  LONG ItemIndex = 0;
71 
72  Info.hRootKey = IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
73 
74  if (RegOpenKeyW(Info.hRootKey,
75  L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
76  &hKey) != ERROR_SUCCESS)
77  {
78  return FALSE;
79  }
80 
81  while (RegEnumKeyExW(hKey, ItemIndex, Info.szKeyName.GetBuffer(MAX_PATH), &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
82  {
83  Info.szKeyName.ReleaseBuffer();
84  if (RegOpenKeyW(hKey, Info.szKeyName.GetString(), &Info.hSubKey) == ERROR_SUCCESS)
85  {
86  dwType = REG_DWORD;
87  dwSize = sizeof(DWORD);
88 
89  if (RegQueryValueExW(Info.hSubKey,
90  L"SystemComponent",
91  NULL,
92  &dwType,
93  (LPBYTE) &dwValue,
94  &dwSize) == ERROR_SUCCESS)
95  {
96  bIsSystemComponent = (dwValue == 0x1);
97  }
98  else
99  {
100  bIsSystemComponent = FALSE;
101  }
102 
103  dwType = REG_SZ;
104  dwSize = MAX_PATH * sizeof(WCHAR);
105  bIsUpdate = (RegQueryValueExW(Info.hSubKey,
106  L"ParentKeyName",
107  NULL,
108  &dwType,
109  (LPBYTE) szParentKeyName.GetBuffer(MAX_PATH),
110  &dwSize) == ERROR_SUCCESS);
111  szParentKeyName.ReleaseBuffer();
112 
113  dwType = REG_SZ;
114  dwSize = MAX_PATH * sizeof(WCHAR);
115  if (RegQueryValueExW(Info.hSubKey,
116  L"DisplayName",
117  NULL,
118  &dwType,
119  (LPBYTE) szDisplayName.GetBuffer(MAX_PATH),
120  &dwSize) == ERROR_SUCCESS)
121  {
122  szDisplayName.ReleaseBuffer();
123  if (EnumType < ENUM_ALL_INSTALLED || EnumType > ENUM_UPDATES)
124  EnumType = ENUM_ALL_INSTALLED;
125 
126  if (!bIsSystemComponent)
127  {
128  if ((EnumType == ENUM_ALL_INSTALLED) || /* All components */
129  ((EnumType == ENUM_INSTALLED_APPLICATIONS) && (!bIsUpdate)) || /* Applications only */
130  ((EnumType == ENUM_UPDATES) && (bIsUpdate))) /* Updates only */
131  {
132  if (!lpEnumProc(ItemIndex, szDisplayName, &Info, param))
133  break;
134  }
135  else
136  {
137  RegCloseKey(Info.hSubKey);
138  }
139  }
140  else
141  {
142  RegCloseKey(Info.hSubKey);
143  }
144  }
145  else
146  {
147  szDisplayName.ReleaseBuffer();
148  RegCloseKey(Info.hSubKey);
149  }
150  }
151 
152  dwSize = MAX_PATH;
153  ItemIndex++;
154  }
155 
156  Info.szKeyName.ReleaseBuffer();
157  RegCloseKey(hKey);
158 
159  return TRUE;
160 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define HKEY_CURRENT_USER
Definition: winreg.h:11
static WCHAR String[]
Definition: stringtable.c:55
BOOL GetApplicationString(LPCWSTR lpKeyName, ATL::CStringW &String)
Definition: installed.cpp:15
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:56
BOOL StartProcess(ATL::CStringW &Path, BOOL Wait)
Definition: misc.cpp:113
struct TraceInfo Info
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
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3296
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
smooth NULL
Definition: ftsmooth.c:416
BOOL(CALLBACK * APPENUMPROC)(INT ItemIndex, ATL::CStringW &Name, PINSTALLED_INFO Info, PVOID param)
Definition: installed.h:16
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
HKEY hSubKey
Definition: installed.h:9
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
static const WCHAR szUninstall[]
Definition: registry.c:162
LPCWSTR szPath
Definition: env.c:35
HRESULT GetString(REFGUID guidKey, [out, size_is(cchBufSize)] LPWSTR pwszValue, UINT32 cchBufSize, [in, out, ptr] UINT32 *pcchLength)
BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc, PVOID param)
Definition: installed.cpp:62
BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR szString)
Definition: installed.cpp:22
BOOL UninstallApplication(PINSTALLED_INFO ItemInfo, BOOL bModify)
Definition: installed.cpp:40
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:2527
WCHAR * LPWSTR
Definition: xmlstorage.h:184
GLuint64EXT * result
Definition: glext.h:11304
#define REG_DWORD
Definition: sdbapi.c:596
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22