Source code to find out all the programs that are installed in a Windows Mobile device and that can be un-Installed
====>SiteMap of this Blog<===
Source code to find out all the programs that are installed in a Windows Mobile device and that can be un-Installed
In the post "Programmatically find out all the programs that can be unInstalled in Windows Mobile devices", I showed how to locate a list of programs installed in a Windows Mobile device. Pocket PC 2003 and other newer platforms (Smartphone 2003, Pocket PC 5.0, and Smartphone 5.0) have to be handled differently.
A reader actually sent me an email for the source code. Oh well this is an easy one so I am posting here:
#include "cfgmgrapi.h"
HRESULT QueryAllInstalled_DM()
{
LPTSTR szProvXMLOut = NULL;
TCHAR szProvXMLIn[512];
memset(szProvXMLIn, 0, 512*sizeof(TCHAR));
wcscat(szProvXMLIn, TEXT("<wap-provisioningdoc><characteristic-query type=\"UnInstall\">"));
wcscat(szProvXMLIn, TEXT("</characteristic-query></wap-provisioningdoc>"));
HRESULT hr = DMProcessConfigXML(szProvXMLIn, CFGFLAG_PROCESS, &szProvXMLOut);
if (!FAILED(hr)) {
ALERT2(TEXT("SUCCESS"), TEXT("DM"));
} else {
ALERT2(TEXT("FAILED"), TEXT("DM"));
}
ALERT2(szProvXMLOut, TEXT("DM"));
DELETE_STR(szProvXMLOut);
return hr;
}
#define APPS_REGHOME TEXT("\\Software\\Apps")
static HRESULT QueryAllInstalled_Registry()
{
HRESULT hr = E_FAIL;
LRESULT lr = E_FAIL;
HKEY hKey = NULL;
DWORD dwcSubKeys = 0; // Number of sub keys
DWORD dwcMaxSubKeyName = 0; // Longest sub key name
TCHAR* szSubKeyName = NULL; // subkey names
DWORD j = 0;
// Open the predefined registry
lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, APPS_REGHOME, 0, 0, &hKey);
if (ERROR_SUCCESS != lr) {
goto FuncExit;
}
// Get Value count.
lr = RegQueryInfoKey(hKey, // Key handle.
NULL, // Buffer for class name.
NULL, // Length of class string.
NULL, // Reserved.
&dwcSubKeys, // Number of sub keys.
&dwcMaxSubKeyName, // Longest sub key size.
NULL, // Longest class string.
NULL, // Number of values for this key.
NULL, // Longest Value name.
NULL, // Longest Value data.
NULL, // Security descriptor.
NULL); // Last write time.
// Enumerate the sub keys
if (!dwcSubKeys || dwcMaxSubKeyName <= 0) {
goto FuncExit;
}
szSubKeyName = new TCHAR[dwcMaxSubKeyName+1];
if (NULL == szSubKeyName) {
goto FuncExit;
}
for (j = 0, lr = ERROR_SUCCESS; j < dwcSubKeys; j++)
{
DWORD dwcSubKeyName = dwcMaxSubKeyName;
memset(szSubKeyName, 0, sizeof(TCHAR)*(dwcMaxSubKeyName+1));
HKEY hSubKey = NULL;
lr = RegEnumKeyEx(
hKey,
j,
szSubKeyName,
&dwcSubKeyName,
NULL,
NULL,
NULL,
NULL);
if (ERROR_SUCCESS != lr) {
continue;
}
// now we have the key name. let us open it.
lr = RegOpenKeyEx(hKey, szSubKeyName, 0, 0, &hSubKey);
if (ERROR_SUCCESS != lr) {
continue;
}
DWORD dwInstl = 0;
DWORD dwValueType = REG_DWORD;
DWORD dwValueLen = sizeof(DWORD);
lr = RegQueryValueEx(hSubKey, TEXT("Instl"), NULL, &dwValueType, (LPBYTE)&dwInstl, &dwValueLen);
if (ERROR_SUCCESS == lr) {
if (dwInstl == 1) {
ALERT2(szSubKeyName, TEXT("From Registry"));
}
}
RegCloseKey(hSubKey);
}
FuncExit:
if (szSubKeyName) {
delete []szSubKeyName;
}
if (hKey) {
RegCloseKey(hKey);
}
return hr;
}
Category: [Setup / Install / unInstall / Upgrade]
0 Comments:
Post a Comment
<< Home