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 BOOL
EnumInstalledApplications(INT EnumType
, BOOL IsUserKey
, APPENUMPROC lpEnumProc
, PVOID param
)
97 DWORD dwSize
= MAX_PATH
, dwType
, dwValue
;
98 BOOL bIsSystemComponent
, bIsUpdate
;
99 ATL::CStringW szParentKeyName
;
100 ATL::CStringW szDisplayName
;
105 Info
.hRootKey
= IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
;
107 if (RegOpenKeyW(Info
.hRootKey
,
108 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
109 &hKey
) != ERROR_SUCCESS
)
114 while (RegEnumKeyExW(hKey
, ItemIndex
, Info
.szKeyName
.GetBuffer(MAX_PATH
), &dwSize
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
116 Info
.szKeyName
.ReleaseBuffer();
117 if (RegOpenKeyW(hKey
, Info
.szKeyName
.GetString(), &Info
.hSubKey
) == ERROR_SUCCESS
)
120 dwSize
= sizeof(DWORD
);
122 if (RegQueryValueExW(Info
.hSubKey
,
127 &dwSize
) == ERROR_SUCCESS
)
129 bIsSystemComponent
= (dwValue
== 0x1);
133 bIsSystemComponent
= FALSE
;
137 dwSize
= MAX_PATH
* sizeof(WCHAR
);
138 bIsUpdate
= (RegQueryValueExW(Info
.hSubKey
,
142 (LPBYTE
) szParentKeyName
.GetBuffer(MAX_PATH
),
143 &dwSize
) == ERROR_SUCCESS
);
144 szParentKeyName
.ReleaseBuffer();
147 dwSize
= MAX_PATH
* sizeof(WCHAR
);
148 if (RegQueryValueExW(Info
.hSubKey
,
152 (LPBYTE
) szDisplayName
.GetBuffer(MAX_PATH
),
153 &dwSize
) == ERROR_SUCCESS
)
155 szDisplayName
.ReleaseBuffer();
156 if (EnumType
< ENUM_ALL_INSTALLED
|| EnumType
> ENUM_UPDATES
)
157 EnumType
= ENUM_ALL_INSTALLED
;
159 if (!bIsSystemComponent
)
161 if ((EnumType
== ENUM_ALL_INSTALLED
) || /* All components */
162 ((EnumType
== ENUM_INSTALLED_APPLICATIONS
) && (!bIsUpdate
)) || /* Applications only */
163 ((EnumType
== ENUM_UPDATES
) && (bIsUpdate
))) /* Updates only */
165 if (!lpEnumProc(ItemIndex
, szDisplayName
, &Info
, param
))
170 RegCloseKey(Info
.hSubKey
);
175 RegCloseKey(Info
.hSubKey
);
180 szDisplayName
.ReleaseBuffer();
181 RegCloseKey(Info
.hSubKey
);
189 Info
.szKeyName
.ReleaseBuffer();