Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygeninstalled.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Applications Manager 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: base/applications/rapps/installed.c 00005 * PURPOSE: Functions for working with installed applications 00006 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org) 00007 */ 00008 00009 #include "rapps.h" 00010 00011 00012 BOOL 00013 GetApplicationString(HKEY hKey, LPWSTR lpKeyName, LPWSTR lpString) 00014 { 00015 DWORD dwSize = MAX_PATH; 00016 00017 if (RegQueryValueExW(hKey, 00018 lpKeyName, 00019 NULL, 00020 NULL, 00021 (LPBYTE)lpString, 00022 &dwSize) == ERROR_SUCCESS) 00023 { 00024 return TRUE; 00025 } 00026 00027 wcscpy(lpString, L"---"); 00028 00029 return FALSE; 00030 } 00031 00032 00033 BOOL 00034 IsInstalledApplication(LPWSTR lpRegName, BOOL IsUserKey) 00035 { 00036 DWORD dwSize = MAX_PATH, dwType; 00037 WCHAR szName[MAX_PATH]; 00038 WCHAR szDisplayName[MAX_PATH]; 00039 HKEY hKey, hSubKey; 00040 INT ItemIndex = 0; 00041 00042 if (RegOpenKeyW(IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, 00043 L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 00044 &hKey) != ERROR_SUCCESS) 00045 { 00046 return FALSE; 00047 } 00048 00049 while (RegEnumKeyExW(hKey, ItemIndex, szName, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) 00050 { 00051 if (RegOpenKeyW(hKey, szName, &hSubKey) == ERROR_SUCCESS) 00052 { 00053 dwType = REG_SZ; 00054 dwSize = MAX_PATH; 00055 if (RegQueryValueExW(hSubKey, 00056 L"DisplayName", 00057 NULL, 00058 &dwType, 00059 (LPBYTE)szDisplayName, 00060 &dwSize) == ERROR_SUCCESS) 00061 { 00062 if (wcscmp(szDisplayName, lpRegName) == 0) 00063 { 00064 RegCloseKey(hSubKey); 00065 RegCloseKey(hKey); 00066 return TRUE; 00067 } 00068 } 00069 } 00070 00071 RegCloseKey(hSubKey); 00072 dwSize = MAX_PATH; 00073 ItemIndex++; 00074 } 00075 00076 RegCloseKey(hKey); 00077 return FALSE; 00078 } 00079 00080 00081 BOOL 00082 UninstallApplication(INT Index, BOOL bModify) 00083 { 00084 WCHAR szModify[] = L"ModifyPath"; 00085 WCHAR szUninstall[] = L"UninstallString"; 00086 WCHAR szPath[MAX_PATH]; 00087 WCHAR szAppName[MAX_STR_LEN]; 00088 DWORD dwType, dwSize; 00089 INT ItemIndex; 00090 LVITEM Item; 00091 HKEY hKey; 00092 PINSTALLED_INFO ItemInfo; 00093 00094 if (!IS_INSTALLED_ENUM(SelectedEnumType)) 00095 return FALSE; 00096 00097 if (Index == -1) 00098 { 00099 ItemIndex = (INT) SendMessageW(hListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED); 00100 if (ItemIndex == -1) 00101 return FALSE; 00102 } 00103 else 00104 { 00105 ItemIndex = Index; 00106 } 00107 00108 ListView_GetItemText(hListView, ItemIndex, 0, szAppName, sizeof(szAppName) / sizeof(WCHAR)); 00109 WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_REMOVE, szAppName); 00110 00111 ZeroMemory(&Item, sizeof(LVITEM)); 00112 00113 Item.mask = LVIF_PARAM; 00114 Item.iItem = ItemIndex; 00115 if (!ListView_GetItem(hListView, &Item)) 00116 return FALSE; 00117 00118 ItemInfo = (PINSTALLED_INFO)Item.lParam; 00119 hKey = ItemInfo->hSubKey; 00120 00121 dwType = REG_SZ; 00122 dwSize = MAX_PATH; 00123 if (RegQueryValueExW(hKey, 00124 bModify ? szModify : szUninstall, 00125 NULL, 00126 &dwType, 00127 (LPBYTE)szPath, 00128 &dwSize) != ERROR_SUCCESS) 00129 { 00130 return FALSE; 00131 } 00132 00133 return StartProcess(szPath, TRUE); 00134 } 00135 00136 00137 BOOL 00138 ShowInstalledAppInfo(INT Index) 00139 { 00140 WCHAR szText[MAX_PATH], szInfo[MAX_PATH]; 00141 PINSTALLED_INFO Info = ListViewGetlParam(Index); 00142 00143 if (!Info || !Info->hSubKey) return FALSE; 00144 00145 GetApplicationString(Info->hSubKey, L"DisplayName", szText); 00146 NewRichEditText(szText, CFE_BOLD); 00147 00148 InsertRichEditText(L"\n", 0); 00149 00150 #define GET_INFO(a, b, c, d) \ 00151 if (GetApplicationString(Info->hSubKey, a, szInfo)) \ 00152 { \ 00153 LoadStringW(hInst, b, szText, sizeof(szText) / sizeof(WCHAR)); \ 00154 InsertRichEditText(szText, c); \ 00155 InsertRichEditText(szInfo, d); \ 00156 } \ 00157 00158 GET_INFO(L"DisplayVersion", IDS_INFO_VERSION, CFE_BOLD, 0); 00159 GET_INFO(L"Publisher", IDS_INFO_PUBLISHER, CFE_BOLD, 0); 00160 GET_INFO(L"RegOwner", IDS_INFO_REGOWNER, CFE_BOLD, 0); 00161 GET_INFO(L"ProductID", IDS_INFO_PRODUCTID, CFE_BOLD, 0); 00162 GET_INFO(L"HelpLink", IDS_INFO_HELPLINK, CFE_BOLD, CFM_LINK); 00163 GET_INFO(L"HelpTelephone", IDS_INFO_HELPPHONE, CFE_BOLD, 0); 00164 GET_INFO(L"Readme", IDS_INFO_README, CFE_BOLD, 0); 00165 GET_INFO(L"Contact", IDS_INFO_CONTACT, CFE_BOLD, 0); 00166 GET_INFO(L"URLUpdateInfo", IDS_INFO_UPDATEINFO, CFE_BOLD, CFM_LINK); 00167 GET_INFO(L"URLInfoAbout", IDS_INFO_INFOABOUT, CFE_BOLD, CFM_LINK); 00168 GET_INFO(L"Comments", IDS_INFO_COMMENTS, CFE_BOLD, 0); 00169 GET_INFO(L"InstallDate", IDS_INFO_INSTALLDATE, CFE_BOLD, 0); 00170 GET_INFO(L"InstallLocation", IDS_INFO_INSTLOCATION, CFE_BOLD, 0); 00171 GET_INFO(L"InstallSource", IDS_INFO_INSTALLSRC, CFE_BOLD, 0); 00172 GET_INFO(L"UninstallString", IDS_INFO_UNINSTALLSTR, CFE_BOLD, 0); 00173 GET_INFO(L"InstallSource", IDS_INFO_INSTALLSRC, CFE_BOLD, 0); 00174 GET_INFO(L"ModifyPath", IDS_INFO_MODIFYPATH, CFE_BOLD, 0); 00175 00176 return TRUE; 00177 } 00178 00179 00180 VOID 00181 RemoveAppFromRegistry(INT Index) 00182 { 00183 PINSTALLED_INFO Info; 00184 WCHAR szFullName[MAX_PATH] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"; 00185 WCHAR szMsgText[MAX_STR_LEN], szMsgTitle[MAX_STR_LEN]; 00186 INT ItemIndex = SendMessage(hListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED); 00187 00188 if (!IS_INSTALLED_ENUM(SelectedEnumType)) 00189 return; 00190 00191 Info = ListViewGetlParam(Index); 00192 if (!Info || !Info->hSubKey || (ItemIndex == -1)) return; 00193 00194 if (!LoadStringW(hInst, IDS_APP_REG_REMOVE, szMsgText, sizeof(szMsgText) / sizeof(WCHAR)) || 00195 !LoadStringW(hInst, IDS_INFORMATION, szMsgTitle, sizeof(szMsgTitle) / sizeof(WCHAR))) 00196 return; 00197 00198 if (MessageBoxW(hMainWnd, szMsgText, szMsgTitle, MB_YESNO | MB_ICONQUESTION) == IDYES) 00199 { 00200 wcsncat(szFullName, Info->szKeyName, MAX_PATH - wcslen(szFullName)); 00201 00202 if (RegDeleteKeyW(Info->hRootKey, szFullName) == ERROR_SUCCESS) 00203 { 00204 (VOID) ListView_DeleteItem(hListView, ItemIndex); 00205 return; 00206 } 00207 00208 if (!LoadStringW(hInst, IDS_UNABLE_TO_REMOVE, szMsgText, sizeof(szMsgText) / sizeof(WCHAR))) 00209 return; 00210 00211 MessageBoxW(hMainWnd, szMsgText, NULL, MB_OK | MB_ICONERROR); 00212 } 00213 } 00214 00215 00216 BOOL 00217 EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc) 00218 { 00219 DWORD dwSize = MAX_PATH, dwType, dwValue; 00220 BOOL bIsSystemComponent, bIsUpdate; 00221 WCHAR pszParentKeyName[MAX_PATH]; 00222 WCHAR pszDisplayName[MAX_PATH]; 00223 INSTALLED_INFO Info; 00224 HKEY hKey; 00225 LONG ItemIndex = 0; 00226 00227 Info.hRootKey = IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 00228 00229 if (RegOpenKeyW(Info.hRootKey, 00230 L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 00231 &hKey) != ERROR_SUCCESS) 00232 { 00233 return FALSE; 00234 } 00235 00236 while (RegEnumKeyExW(hKey, ItemIndex, Info.szKeyName, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) 00237 { 00238 if (RegOpenKeyW(hKey, Info.szKeyName, &Info.hSubKey) == ERROR_SUCCESS) 00239 { 00240 dwType = REG_DWORD; 00241 dwSize = sizeof(DWORD); 00242 00243 if (RegQueryValueExW(Info.hSubKey, 00244 L"SystemComponent", 00245 NULL, 00246 &dwType, 00247 (LPBYTE)&dwValue, 00248 &dwSize) == ERROR_SUCCESS) 00249 { 00250 bIsSystemComponent = (dwValue == 0x1); 00251 } 00252 else 00253 { 00254 bIsSystemComponent = FALSE; 00255 } 00256 00257 dwType = REG_SZ; 00258 dwSize = MAX_PATH; 00259 bIsUpdate = (RegQueryValueExW(Info.hSubKey, 00260 L"ParentKeyName", 00261 NULL, 00262 &dwType, 00263 (LPBYTE)pszParentKeyName, 00264 &dwSize) == ERROR_SUCCESS); 00265 00266 dwSize = MAX_PATH; 00267 if (RegQueryValueExW(Info.hSubKey, 00268 L"DisplayName", 00269 NULL, 00270 &dwType, 00271 (LPBYTE)pszDisplayName, 00272 &dwSize) == ERROR_SUCCESS) 00273 { 00274 if (EnumType < ENUM_ALL_COMPONENTS || EnumType > ENUM_UPDATES) 00275 EnumType = ENUM_ALL_COMPONENTS; 00276 00277 if (!bIsSystemComponent) 00278 { 00279 if ((EnumType == ENUM_ALL_COMPONENTS) || /* All components */ 00280 ((EnumType == ENUM_APPLICATIONS) && (!bIsUpdate)) || /* Applications only */ 00281 ((EnumType == ENUM_UPDATES) && (bIsUpdate))) /* Updates only */ 00282 { 00283 if (!lpEnumProc(ItemIndex, pszDisplayName, Info)) 00284 break; 00285 } 00286 } 00287 } 00288 } 00289 00290 dwSize = MAX_PATH; 00291 ItemIndex++; 00292 } 00293 00294 RegCloseKey(hKey); 00295 00296 return TRUE; 00297 } Generated on Sat May 26 2012 04:16:16 for ReactOS by
1.7.6.1
|