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"
15 BOOL
INSTALLED_INFO::GetApplicationString(LPCWSTR lpKeyName
, ATL::CStringW
& String
)
17 BOOL result
= ::GetApplicationString(hSubKey
, lpKeyName
, String
.GetBuffer(MAX_PATH
));
18 String
.ReleaseBuffer();
22 BOOL
GetApplicationString(HKEY hKey
, LPCWSTR lpKeyName
, LPWSTR szString
)
24 DWORD dwSize
= MAX_PATH
* sizeof(WCHAR
);
26 if (RegQueryValueExW(hKey
,
31 &dwSize
) == ERROR_SUCCESS
)
36 StringCchCopyW(szString
, MAX_PATH
, L
"---");
40 BOOL
UninstallApplication(PINSTALLED_INFO ItemInfo
, BOOL bModify
)
42 LPCWSTR szModify
= L
"ModifyPath";
43 LPCWSTR szUninstall
= L
"UninstallString";
45 WCHAR szPath
[MAX_PATH
];
48 dwSize
= MAX_PATH
* sizeof(WCHAR
);
49 if (RegQueryValueExW(ItemInfo
->hSubKey
,
50 bModify
? szModify
: szUninstall
,
54 &dwSize
) != ERROR_SUCCESS
)
59 return StartProcess(szPath
, TRUE
);
62 BOOL
EnumInstalledApplications(INT EnumType
, BOOL IsUserKey
, APPENUMPROC lpEnumProc
, PVOID param
)
64 DWORD dwSize
= MAX_PATH
, dwType
, dwValue
;
65 BOOL bIsSystemComponent
, bIsUpdate
;
66 ATL::CStringW szParentKeyName
;
67 ATL::CStringW szDisplayName
;
72 Info
.hRootKey
= IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
;
74 if (RegOpenKeyW(Info
.hRootKey
,
75 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
76 &hKey
) != ERROR_SUCCESS
)
81 while (RegEnumKeyExW(hKey
, ItemIndex
, Info
.szKeyName
.GetBuffer(MAX_PATH
), &dwSize
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
83 Info
.szKeyName
.ReleaseBuffer();
84 if (RegOpenKeyW(hKey
, Info
.szKeyName
.GetString(), &Info
.hSubKey
) == ERROR_SUCCESS
)
87 dwSize
= sizeof(DWORD
);
89 if (RegQueryValueExW(Info
.hSubKey
,
94 &dwSize
) == ERROR_SUCCESS
)
96 bIsSystemComponent
= (dwValue
== 0x1);
100 bIsSystemComponent
= FALSE
;
104 dwSize
= MAX_PATH
* sizeof(WCHAR
);
105 bIsUpdate
= (RegQueryValueExW(Info
.hSubKey
,
109 (LPBYTE
) szParentKeyName
.GetBuffer(MAX_PATH
),
110 &dwSize
) == ERROR_SUCCESS
);
111 szParentKeyName
.ReleaseBuffer();
114 dwSize
= MAX_PATH
* sizeof(WCHAR
);
115 if (RegQueryValueExW(Info
.hSubKey
,
119 (LPBYTE
) szDisplayName
.GetBuffer(MAX_PATH
),
120 &dwSize
) == ERROR_SUCCESS
)
122 szDisplayName
.ReleaseBuffer();
123 if (EnumType
< ENUM_ALL_INSTALLED
|| EnumType
> ENUM_UPDATES
)
124 EnumType
= ENUM_ALL_INSTALLED
;
126 if (!bIsSystemComponent
)
128 if ((EnumType
== ENUM_ALL_INSTALLED
) || /* All components */
129 ((EnumType
== ENUM_INSTALLED_APPLICATIONS
) && (!bIsUpdate
)) || /* Applications only */
130 ((EnumType
== ENUM_UPDATES
) && (bIsUpdate
))) /* Updates only */
132 if (!lpEnumProc(ItemIndex
, szDisplayName
, &Info
, param
))
137 RegCloseKey(Info
.hSubKey
);
142 RegCloseKey(Info
.hSubKey
);
147 szDisplayName
.ReleaseBuffer();
148 RegCloseKey(Info
.hSubKey
);
156 Info
.szKeyName
.ReleaseBuffer();