2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/installed.cpp
5 * PURPOSE: Functions for working with installed applications
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
12 GetApplicationString(HKEY hKey
, LPCWSTR lpKeyName
, LPWSTR lpString
)
14 DWORD dwSize
= MAX_PATH
* sizeof(WCHAR
);
16 if (RegQueryValueExW(hKey
,
21 &dwSize
) == ERROR_SUCCESS
)
26 (VOID
)StringCchCopyW(lpString
, MAX_PATH
, L
"---");
32 IsInstalledApplicationEx(LPWSTR lpRegName
, BOOL IsUserKey
, REGSAM keyWow
)
34 DWORD dwSize
= MAX_PATH
, dwType
;
35 WCHAR szName
[MAX_PATH
];
36 WCHAR szDisplayName
[MAX_PATH
];
40 if (RegOpenKeyExW(IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
,
41 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 0, keyWow
| KEY_ENUMERATE_SUB_KEYS
,
42 &hKey
) != ERROR_SUCCESS
)
47 while (RegEnumKeyExW(hKey
, ItemIndex
, szName
, &dwSize
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
49 if (RegOpenKeyExW(hKey
, szName
, 0, keyWow
| KEY_READ
, &hSubKey
) == ERROR_SUCCESS
)
53 dwSize
= sizeof(szDisplayName
);
54 if (RegQueryValueExW(hSubKey
,
58 (LPBYTE
)szDisplayName
,
59 &dwSize
) == ERROR_SUCCESS
)
61 if (wcscmp(szDisplayName
, lpRegName
) == 0)
79 UninstallApplication(INT Index
, BOOL bModify
)
81 WCHAR szModify
[] = L
"ModifyPath";
82 WCHAR szUninstall
[] = L
"UninstallString";
83 WCHAR szPath
[MAX_PATH
];
84 WCHAR szAppName
[MAX_STR_LEN
];
89 PINSTALLED_INFO ItemInfo
;
91 if (!IS_INSTALLED_ENUM(SelectedEnumType
))
96 ItemIndex
= (INT
) SendMessageW(hListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
105 ListView_GetItemText(hListView
, ItemIndex
, 0, szAppName
, _countof(szAppName
));
106 WriteLogMessage(EVENTLOG_SUCCESS
, MSG_SUCCESS_REMOVE
, szAppName
);
108 ZeroMemory(&Item
, sizeof(Item
));
110 Item
.mask
= LVIF_PARAM
;
111 Item
.iItem
= ItemIndex
;
112 if (!ListView_GetItem(hListView
, &Item
))
115 ItemInfo
= (PINSTALLED_INFO
)Item
.lParam
;
116 hKey
= ItemInfo
->hSubKey
;
119 dwSize
= sizeof(szPath
);
120 if (RegQueryValueExW(hKey
,
121 bModify
? szModify
: szUninstall
,
125 &dwSize
) != ERROR_SUCCESS
)
130 return StartProcess(szPath
, TRUE
);
135 ShowInstalledAppInfo(INT Index
)
137 WCHAR szText
[MAX_PATH
], szInfo
[MAX_PATH
];
138 PINSTALLED_INFO Info
= (PINSTALLED_INFO
) ListViewGetlParam(Index
);
140 if (!Info
|| !Info
->hSubKey
) return FALSE
;
142 GetApplicationString(Info
->hSubKey
, L
"DisplayName", szText
);
143 NewRichEditText(szText
, CFE_BOLD
);
145 InsertRichEditText(L
"\n", 0);
147 #define GET_INFO(a, b, c, d) \
148 if (GetApplicationString(Info->hSubKey, a, szInfo)) \
150 LoadStringW(hInst, b, szText, _countof(szText)); \
151 InsertRichEditText(szText, c); \
152 InsertRichEditText(szInfo, d); \
155 GET_INFO(L"DisplayVersion", IDS_INFO_VERSION, CFE_BOLD, 0);
156 GET_INFO(L
"Publisher", IDS_INFO_PUBLISHER
, CFE_BOLD
, 0);
157 GET_INFO(L
"RegOwner", IDS_INFO_REGOWNER
, CFE_BOLD
, 0);
158 GET_INFO(L
"ProductID", IDS_INFO_PRODUCTID
, CFE_BOLD
, 0);
159 GET_INFO(L
"HelpLink", IDS_INFO_HELPLINK
, CFE_BOLD
, CFM_LINK
);
160 GET_INFO(L
"HelpTelephone", IDS_INFO_HELPPHONE
, CFE_BOLD
, 0);
161 GET_INFO(L
"Readme", IDS_INFO_README
, CFE_BOLD
, 0);
162 GET_INFO(L
"Contact", IDS_INFO_CONTACT
, CFE_BOLD
, 0);
163 GET_INFO(L
"URLUpdateInfo", IDS_INFO_UPDATEINFO
, CFE_BOLD
, CFM_LINK
);
164 GET_INFO(L
"URLInfoAbout", IDS_INFO_INFOABOUT
, CFE_BOLD
, CFM_LINK
);
165 GET_INFO(L
"Comments", IDS_INFO_COMMENTS
, CFE_BOLD
, 0);
166 GET_INFO(L
"InstallDate", IDS_INFO_INSTALLDATE
, CFE_BOLD
, 0);
167 GET_INFO(L
"InstallLocation", IDS_INFO_INSTLOCATION
, CFE_BOLD
, 0);
168 GET_INFO(L
"InstallSource", IDS_INFO_INSTALLSRC
, CFE_BOLD
, 0);
169 GET_INFO(L
"UninstallString", IDS_INFO_UNINSTALLSTR
, CFE_BOLD
, 0);
170 GET_INFO(L
"InstallSource", IDS_INFO_INSTALLSRC
, CFE_BOLD
, 0);
171 GET_INFO(L
"ModifyPath", IDS_INFO_MODIFYPATH
, CFE_BOLD
, 0);
178 RemoveAppFromRegistry(INT Index
)
180 PINSTALLED_INFO Info
;
181 WCHAR szFullName
[MAX_PATH
] = L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
182 WCHAR szMsgText
[MAX_STR_LEN
], szMsgTitle
[MAX_STR_LEN
];
183 INT ItemIndex
= SendMessage(hListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
185 if (!IS_INSTALLED_ENUM(SelectedEnumType
))
188 Info
= (PINSTALLED_INFO
) ListViewGetlParam(Index
);
189 if (!Info
|| !Info
->hSubKey
|| (ItemIndex
== -1)) return;
191 if (!LoadStringW(hInst
, IDS_APP_REG_REMOVE
, szMsgText
, _countof(szMsgText
)) ||
192 !LoadStringW(hInst
, IDS_INFORMATION
, szMsgTitle
, _countof(szMsgTitle
)))
195 if (MessageBoxW(hMainWnd
, szMsgText
, szMsgTitle
, MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
197 wcsncat(szFullName
, Info
->szKeyName
, MAX_PATH
- wcslen(szFullName
));
199 if (RegDeleteKeyW(Info
->hRootKey
, szFullName
) == ERROR_SUCCESS
)
201 (VOID
) ListView_DeleteItem(hListView
, ItemIndex
);
205 if (!LoadStringW(hInst
, IDS_UNABLE_TO_REMOVE
, szMsgText
, _countof(szMsgText
)))
208 MessageBoxW(hMainWnd
, szMsgText
, NULL
, MB_OK
| MB_ICONERROR
);
214 EnumInstalledApplications(INT EnumType
, BOOL IsUserKey
, APPENUMPROC lpEnumProc
)
216 DWORD dwSize
= MAX_PATH
, dwType
, dwValue
;
217 BOOL bIsSystemComponent
, bIsUpdate
;
218 WCHAR pszParentKeyName
[MAX_PATH
];
219 WCHAR pszDisplayName
[MAX_PATH
];
224 Info
.hRootKey
= IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
;
226 if (RegOpenKeyW(Info
.hRootKey
,
227 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
228 &hKey
) != ERROR_SUCCESS
)
233 while (RegEnumKeyExW(hKey
, ItemIndex
, Info
.szKeyName
, &dwSize
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
235 if (RegOpenKeyW(hKey
, Info
.szKeyName
, &Info
.hSubKey
) == ERROR_SUCCESS
)
238 dwSize
= sizeof(DWORD
);
240 if (RegQueryValueExW(Info
.hSubKey
,
245 &dwSize
) == ERROR_SUCCESS
)
247 bIsSystemComponent
= (dwValue
== 0x1);
251 bIsSystemComponent
= FALSE
;
255 dwSize
= sizeof(pszParentKeyName
);
256 bIsUpdate
= (RegQueryValueExW(Info
.hSubKey
,
260 (LPBYTE
)pszParentKeyName
,
261 &dwSize
) == ERROR_SUCCESS
);
263 dwSize
= sizeof(pszDisplayName
);
264 if (RegQueryValueExW(Info
.hSubKey
,
268 (LPBYTE
)pszDisplayName
,
269 &dwSize
) == ERROR_SUCCESS
)
271 if (EnumType
< ENUM_ALL_COMPONENTS
|| EnumType
> ENUM_UPDATES
)
272 EnumType
= ENUM_ALL_COMPONENTS
;
274 if (!bIsSystemComponent
)
276 if ((EnumType
== ENUM_ALL_COMPONENTS
) || /* All components */
277 ((EnumType
== ENUM_APPLICATIONS
) && (!bIsUpdate
)) || /* Applications only */
278 ((EnumType
== ENUM_UPDATES
) && (bIsUpdate
))) /* Updates only */
280 if (!lpEnumProc(ItemIndex
, pszDisplayName
, &Info
))
285 RegCloseKey(Info
.hSubKey
);
290 RegCloseKey(Info
.hSubKey
);
295 RegCloseKey(Info
.hSubKey
);