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(PINSTALLED_INFO ItemInfo
, BOOL bModify
)
43 LPCWSTR szModify
= L
"ModifyPath";
44 LPCWSTR szUninstall
= L
"UninstallString";
46 WCHAR szPath
[MAX_PATH
];
49 dwSize
= MAX_PATH
* sizeof(WCHAR
);
50 if (RegQueryValueExW(ItemInfo
->hSubKey
,
51 bModify
? szModify
: szUninstall
,
55 &dwSize
) != ERROR_SUCCESS
)
60 return StartProcess(szPath
, TRUE
);
63 BOOL
EnumInstalledApplications(INT EnumType
, BOOL IsUserKey
, APPENUMPROC lpEnumProc
, PVOID param
)
65 DWORD dwSize
= MAX_PATH
, dwType
, dwValue
;
66 BOOL bIsSystemComponent
, bIsUpdate
;
67 ATL::CStringW szParentKeyName
;
68 ATL::CStringW szDisplayName
;
73 Info
.hRootKey
= IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
;
75 if (RegOpenKeyW(Info
.hRootKey
,
76 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
77 &hKey
) != ERROR_SUCCESS
)
82 while (RegEnumKeyExW(hKey
, ItemIndex
, Info
.szKeyName
.GetBuffer(MAX_PATH
), &dwSize
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
84 Info
.szKeyName
.ReleaseBuffer();
85 if (RegOpenKeyW(hKey
, Info
.szKeyName
.GetString(), &Info
.hSubKey
) == ERROR_SUCCESS
)
88 dwSize
= sizeof(DWORD
);
90 if (RegQueryValueExW(Info
.hSubKey
,
95 &dwSize
) == ERROR_SUCCESS
)
97 bIsSystemComponent
= (dwValue
== 0x1);
101 bIsSystemComponent
= FALSE
;
105 dwSize
= MAX_PATH
* sizeof(WCHAR
);
106 bIsUpdate
= (RegQueryValueExW(Info
.hSubKey
,
110 (LPBYTE
) szParentKeyName
.GetBuffer(MAX_PATH
),
111 &dwSize
) == ERROR_SUCCESS
);
112 szParentKeyName
.ReleaseBuffer();
115 dwSize
= MAX_PATH
* sizeof(WCHAR
);
116 if (RegQueryValueExW(Info
.hSubKey
,
120 (LPBYTE
) szDisplayName
.GetBuffer(MAX_PATH
),
121 &dwSize
) == ERROR_SUCCESS
)
123 szDisplayName
.ReleaseBuffer();
124 if (EnumType
< ENUM_ALL_INSTALLED
|| EnumType
> ENUM_UPDATES
)
125 EnumType
= ENUM_ALL_INSTALLED
;
127 if (!bIsSystemComponent
)
129 if ((EnumType
== ENUM_ALL_INSTALLED
) || /* All components */
130 ((EnumType
== ENUM_INSTALLED_APPLICATIONS
) && (!bIsUpdate
)) || /* Applications only */
131 ((EnumType
== ENUM_UPDATES
) && (bIsUpdate
))) /* Updates only */
133 if (!lpEnumProc(ItemIndex
, szDisplayName
, &Info
, param
))
138 RegCloseKey(Info
.hSubKey
);
143 RegCloseKey(Info
.hSubKey
);
148 szDisplayName
.ReleaseBuffer();
149 RegCloseKey(Info
.hSubKey
);
157 Info
.szKeyName
.ReleaseBuffer();