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 (chaez.san@gmail.com)
11 #include "installed.h"
16 BOOL
GetApplicationString(HKEY hKey
, LPCWSTR lpKeyName
, ATL::CStringW
& String
)
18 BOOL result
= GetApplicationString(hKey
, 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 BOOL
ShowInstalledAppInfo(INT Index
)
99 PINSTALLED_INFO Info
= (PINSTALLED_INFO
) ListViewGetlParam(Index
);
101 if (!Info
|| !Info
->hSubKey
) return FALSE
;
103 GetApplicationString(Info
->hSubKey
, L
"DisplayName", szText
);
104 NewRichEditText(szText
, CFE_BOLD
);
105 InsertRichEditText(L
"\n", 0);
107 #define GET_INFO(a, b, c, d) \
108 if (GetApplicationString(Info->hSubKey, a, szInfo)) \
110 szText.LoadStringW(b); \
111 InsertRichEditText(szText, c); \
112 InsertRichEditText(szInfo, d); \
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);
119 GET_INFO(L
"HelpLink", IDS_INFO_HELPLINK
, CFE_BOLD
, CFM_LINK
);
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);
136 VOID
RemoveAppFromRegistry(INT Index
)
138 PINSTALLED_INFO Info
;
139 WCHAR szFullName
[MAX_PATH
] = L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
140 ATL::CStringW szMsgText
, szMsgTitle
;
141 INT ItemIndex
= SendMessageW(hListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
143 if (!IsInstalledEnum(SelectedEnumType
))
146 Info
= (PINSTALLED_INFO
) ListViewGetlParam(Index
);
147 if (!Info
|| !Info
->hSubKey
|| (ItemIndex
== -1)) return;
149 if (!szMsgText
.LoadStringW(IDS_APP_REG_REMOVE
) ||
150 !szMsgTitle
.LoadStringW(IDS_INFORMATION
))
153 if (MessageBoxW(hMainWnd
, szMsgText
, szMsgTitle
, MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
155 ATL::CStringW::CopyChars(szFullName
,
157 Info
->szKeyName
.GetString(),
158 MAX_PATH
- wcslen(szFullName
));
160 if (RegDeleteKeyW(Info
->hRootKey
, szFullName
) == ERROR_SUCCESS
)
162 ListView_DeleteItem(hListView
, ItemIndex
);
166 if (!szMsgText
.LoadStringW(IDS_UNABLE_TO_REMOVE
))
169 MessageBoxW(hMainWnd
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
173 BOOL
EnumInstalledApplications(INT EnumType
, BOOL IsUserKey
, APPENUMPROC lpEnumProc
)
175 DWORD dwSize
= MAX_PATH
, dwType
, dwValue
;
176 BOOL bIsSystemComponent
, bIsUpdate
;
177 ATL::CStringW szParentKeyName
;
178 ATL::CStringW szDisplayName
;
183 Info
.hRootKey
= IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
;
185 if (RegOpenKeyW(Info
.hRootKey
,
186 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
187 &hKey
) != ERROR_SUCCESS
)
192 while (RegEnumKeyExW(hKey
, ItemIndex
, Info
.szKeyName
.GetBuffer(MAX_PATH
), &dwSize
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
194 Info
.szKeyName
.ReleaseBuffer();
195 if (RegOpenKeyW(hKey
, Info
.szKeyName
.GetString(), &Info
.hSubKey
) == ERROR_SUCCESS
)
198 dwSize
= sizeof(DWORD
);
200 if (RegQueryValueExW(Info
.hSubKey
,
205 &dwSize
) == ERROR_SUCCESS
)
207 bIsSystemComponent
= (dwValue
== 0x1);
211 bIsSystemComponent
= FALSE
;
215 dwSize
= MAX_PATH
* sizeof(WCHAR
);
216 bIsUpdate
= (RegQueryValueExW(Info
.hSubKey
,
220 (LPBYTE
) szParentKeyName
.GetBuffer(MAX_PATH
),
221 &dwSize
) == ERROR_SUCCESS
);
222 szParentKeyName
.ReleaseBuffer();
225 dwSize
= MAX_PATH
* sizeof(WCHAR
);
226 if (RegQueryValueExW(Info
.hSubKey
,
230 (LPBYTE
) szDisplayName
.GetBuffer(MAX_PATH
),
231 &dwSize
) == ERROR_SUCCESS
)
233 szDisplayName
.ReleaseBuffer();
234 if (EnumType
< ENUM_ALL_INSTALLED
|| EnumType
> ENUM_UPDATES
)
235 EnumType
= ENUM_ALL_INSTALLED
;
237 if (!bIsSystemComponent
)
239 if ((EnumType
== ENUM_ALL_INSTALLED
) || /* All components */
240 ((EnumType
== ENUM_INSTALLED_APPLICATIONS
) && (!bIsUpdate
)) || /* Applications only */
241 ((EnumType
== ENUM_UPDATES
) && (bIsUpdate
))) /* Updates only */
243 if (!lpEnumProc(ItemIndex
, szDisplayName
, &Info
))
248 RegCloseKey(Info
.hSubKey
);
253 RegCloseKey(Info
.hSubKey
);
258 szDisplayName
.ReleaseBuffer();
259 RegCloseKey(Info
.hSubKey
);
267 Info
.szKeyName
.ReleaseBuffer();