Windows 系统中,安装程序都可以在注册表

HKEY_LOCAL_MACHINE\SoftWare\Microsoft\Windows\CurrentVersion\Uninstall

获取,并且xp、vista、win7、win8都一样

打开注册表命令:regedit,依次展开上述注册表路径,安装程序列表如下图:



获取系统安装程序列表:

// 获取系统安装程序列表 
 BOOL CMyListCtrlTestDlg::AllRegKey(HKEY hKey, LPCTSTR szDesKeyItem) 
 { 
     HKEY hSubKey; 
     DWORD dwIndex = 0; 
     long lResult; 
     int i = 1; 
  
     lResult = RegOpenKeyEx(hKey, szDesKeyItem, 0, KEY_READ, &hSubKey);      // 打开注册表 
     if(ERROR_SUCCESS == lResult) { 
         TCHAR szKeyName[256] = { 0 }; 
         DWORD cbName = 256*sizeof(TCHAR); 
  
         lResult = RegEnumKeyEx(hSubKey, dwIndex, szKeyName, &cbName, 0, NULL, NULL, NULL);      // 获取字段 
         while (lResult == ERROR_SUCCESS && lResult != ERROR_MORE_DATA){ 
             OutputDebugString(szKeyName); 
  
  
             CString str; 
             str.Format(_T("%d"), i); 
  
             i = m_MyList.InsertItem(i, str);        // 插入到List控件显示 
             m_MyList.SetItemText(i,1,szKeyName); 
  
  
             dwIndex = dwIndex + 1;          // 改变dwIndex,循环获取下移字段 
             cbName = 256*sizeof(TCHAR); 
             lResult = RegEnumKeyEx(hSubKey, dwIndex, szKeyName, &cbName, 0, NULL, NULL, NULL); 
  
             i++; 
  
         } 
         RegCloseKey(hSubKey);       // 关闭注册表 
         return TRUE; 
     } 
     RegCloseKey(hSubKey); 
     return FALSE; 
 } 


获取安装程序属性信息

(二次读取注册表):

BOOL SoftList::AllRegKey(HKEY hKey, LPCTSTR szDesKeyItem)
{
	HKEY hSubKey;
	DWORD dwIndex = 0;
	long lResult;

	lResult = RegOpenKeyEx(hKey, szDesKeyItem, 0, KEY_READ, &hSubKey);		// 打开注册表
	if(ERROR_SUCCESS == lResult) {
		int id = 1;						// 序号
		TCHAR s_name[256] = {0};		// 软件名			
		TCHAR s_DisplayName[256] = {0};			// 显示名称
		TCHAR s_Publisher[256] = {0};			// 发布者
		TCHAR s_InstallDate[12] = {0};			// 安装日期
		DWORD s_EstimatedSize;					// 大小
		TCHAR s_DisplayVersion[256] = { 0 };	// 版本
		DWORD cbName = 256*sizeof(TCHAR);	
		DWORD cbName2 = sizeof(TCHAR);

		DWORD typeSZ = REG_SZ;			// SZ 注册表类型
		DWORD typeDWORD = REG_DWORD;	// DWORD 注册表类型

		lResult = RegEnumKeyEx(hSubKey, dwIndex, s_name, &cbName, 0, NULL, NULL, NULL);		// 获取字段
		while (lResult == ERROR_SUCCESS && lResult != ERROR_MORE_DATA){
			OutputDebugString(s_name);

			CString str;
			str.Format(_T("%d"), id);

			id = m_SoftList.InsertItem(id, str);		// 插入到List控件显示
			m_SoftList.SetItemText(id, 1, s_name);


			HKEY hItem;		// 下一级注册表句柄
			if(::RegOpenKeyEx(hSubKey, s_name, 0, KEY_READ, &hItem) == ERROR_SUCCESS){		// 提取下一级注册表程序的属性信息
				if (::RegQueryValueEx(hItem, _T("DisplayName"), 0, &typeSZ, (LPBYTE)s_DisplayName, &cbName) == ERROR_SUCCESS) {
					m_SoftList.SetItemText(id, 1, s_DisplayName);
				}

				if (::RegQueryValueEx(hItem, _T("Publisher"), 0, &typeSZ, (LPBYTE)s_Publisher, &cbName) == ERROR_SUCCESS) {
					m_SoftList.SetItemText(id, 2, s_Publisher);
				}

				if (::RegQueryValueEx(hItem, _T("InstallDate"), 0, &typeSZ, (LPBYTE)s_InstallDate, &cbName) == ERROR_SUCCESS) {
					if (s_InstallDate != NULL) {		// 判断是否为空
						m_SoftList.SetItemText(id, 3, s_InstallDate);		
					}
				}

				if (::RegQueryValueEx(hItem, _T("EstimatedSize"), 0, &typeDWORD, (LPBYTE)&s_EstimatedSize, &cbName2) == ERROR_SUCCESS) {
					float f_Size = s_EstimatedSize/1024.0;	// DWORD 转换为 CString 类型
					CString p_Size;
					p_Size.Format(_T("%.2f M"), f_Size);
					
					m_SoftList.SetItemText(id, 4, p_Size);
				}

				if (::RegQueryValueEx(hItem, _T("DisplayVersion"), 0, &typeSZ, (LPBYTE)s_DisplayVersion, &cbName) == ERROR_SUCCESS) {
					m_SoftList.SetItemText(id, 5, s_DisplayVersion);
				}
				
				::RegCloseKey(hItem);	// 关闭二级注册表(程序属性信息)
			}


			dwIndex = dwIndex + 1;			// 改变dwIndex,循环获取下移字段
			cbName = 256*sizeof(TCHAR);
			lResult = RegEnumKeyEx(hSubKey, dwIndex, s_name, &cbName, 0, NULL, NULL, NULL);

			id++;

		}
		RegCloseKey(hSubKey);	// 关闭一级注册表(读取程序信息)
		return TRUE;
	}
	RegCloseKey(hSubKey);
	return FALSE;
}


通过注册表路径获取调用:

AllRegKey(HKEY_LOCAL_MACHINE, TEXT("SoftWare\\Microsoft\\Windows\\CurrentVersion\\Uninstall"));


运行结果: