Get Windows 7 Hotfix Infos From Registry

On windows xp ,we can get the hotfix infos form HKEY_LOCAL_MACHINE,(“SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\HotFix”),but on windows 7 there is no that key. however we can get the hotfix  infos from here”HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\”.Click here to down load the source code(not well written).lol

Source code here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
void CWindows7HotFixInfoDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	//CDialogEx::OnOK();
	TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
	DWORD    cbName;                   // size of name string 
	TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
	DWORD    cchClassName = MAX_PATH;  // size of class string 
	DWORD    cSubKeys=0;               // number of subkeys 
	DWORD    cbMaxSubKey;              // longest subkey size 
	DWORD    cchMaxClass;              // longest class string 
	DWORD    cValues;              // number of values for key 
	DWORD    cchMaxValue;          // longest value name 
	DWORD    cbMaxValueData;       // longest value data 
	DWORD    cbSecurityDescriptor; // size of security descriptor 
	FILETIME ftLastWriteTime;      // last write time 
	HKEY hKey;
	DWORD i, retCode; 
	TCHAR  achValue[MAX_VALUE_NAME]; 
	DWORD cchValue = MAX_VALUE_NAME; 
	DWORD HotfixNumber = 0;
	HotFix pFix;
	BOOL bRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
		_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\Packages"),
		0, 
		KEY_READ,
		&hKey);
	// Get the class name and the value count. 
	retCode = RegQueryInfoKey(
		hKey,                    // key handle 
		achClass,                // buffer for class name 
		&cchClassName,           // size of class string 
		NULL,                    // reserved 
		&cSubKeys,               // number of subkeys 
		&cbMaxSubKey,            // longest subkey size 
		&cchMaxClass,            // longest class string 
		&cValues,                // number of values for this key 
		&cchMaxValue,            // longest value name 
		&cbMaxValueData,         // longest value data 
		&cbSecurityDescriptor,   // security descriptor 
		&ftLastWriteTime);       // last write time 
 
	// Enumerate the subkeys, until RegEnumKeyEx fails.
	if (cSubKeys)
	{
 
		for (i=0; i<csubkeys ; i++)		
		{ 
			cbName = MAX_KEY_LENGTH;
			retCode = RegEnumKeyEx(hKey, i,
				achKey, 
				&cbName, 
				NULL, 
				NULL, 
				NULL, 
				&ftLastWriteTime); 
			if (retCode == ERROR_SUCCESS )  //Enumerate the  Values
			{ 
 
				HKEY subKey;
				BOOL bRet = RegOpenKeyEx(hKey,
					achKey,
					0, 
					KEY_QUERY_VALUE,
					&subKey);
				if (bRet == ERROR_SUCCESS)
				{
					DWORD dwBufLen;
					TCHAR InstallClient[255];
					bRet = RegQueryValueEx(subKey,
						_T("InstallClient"),
						NULL,
						NULL,
						(LPBYTE)InstallClient,
						&dwBufLen);
					if (bRet == ERROR_SUCCESS)
					{
						TCHAR TargetClient[255] =_T("WindowsUpdateAgent"); //Get syetem hotfix infos.
						int r= StrCmp(InstallClient,TargetClient);
						if (0 ==r )
						{
							memcpy(pFix.InstallClient,InstallClient,255);
							FILETIME HotFixTime = {0};
							DWORD dwType = REG_DWORD; 
							DWORD InstallTimeLow = 0; 
							DWORD InstallTimeHigh =0 ;
							DWORD dwBufLen;
							bRet= RegQueryValueEx(subKey,	
								_T("InstallTimeLow"),
								NULL,
								&dwType,
								(LPBYTE)&InstallTimeLow,
								&dwBufLen);
							//DWORD errorcode = GetLastError();
							if (bRet == ERROR_SUCCESS)
							{
								pFix.InstallTime.dwLowDateTime = InstallTimeLow;
							}
							bRet= RegQueryValueEx(subKey,
								_T("InstallTimeHigh"),
								NULL,
								&dwType,
								(LPBYTE)&InstallTimeHigh,
								&dwBufLen);
							if (bRet == ERROR_SUCCESS)
							{
								pFix.InstallTime.dwHighDateTime = InstallTimeHigh;
							}
							TCHAR InstallName[256];
							bRet = RegQueryValueEx(subKey,
								_T("InstallName"),
								NULL,
								NULL,
								(LPBYTE)InstallName,
								&dwBufLen);
							if (bRet ==  ERROR_SUCCESS)
							{
								memcpy(pFix.InstallName,InstallName,255);
							}
							TCHAR InstallUser[256];
							bRet = RegQueryValueEx(subKey,
								_T("InstallUser"),
								NULL,
								NULL,
								(LPBYTE)InstallUser,
								&dwBufLen);
							if (bRet ==  ERROR_SUCCESS)
							{
								memcpy(pFix.InstallUser,InstallUser,255);
							}
							TCHAR InstallLocation[512];
							bRet = RegQueryValueEx(subKey,
								_T("InstallLocation"),
								NULL,
								NULL,
								(LPBYTE)InstallLocation,
								&dwBufLen);
							if (bRet ==  ERROR_SUCCESS)
							{
								memcpy(pFix.InstallLocation,InstallLocation,512);
							}
							CString tmp;
							m_datalist.InsertItem(HotfixNumber,_T(""));
							m_datalist.SetItemText(HotfixNumber,0,pFix.InstallName);
							m_datalist.SetItemText(HotfixNumber,1,pFix.InstallClient);
							tmp.AppendFormat(_T("%d %d"),pFix.InstallTime.dwHighDateTime,pFix.InstallTime.dwLowDateTime);
							m_datalist.SetItemText(HotfixNumber,2,tmp);
							m_datalist.SetItemText(HotfixNumber,3,pFix.InstallUser);
							HotfixNumber++;
						}
					}
				}
				RegCloseKey(subKey);
			} 
		}
	} 
	RegCloseKey(hKey);
}

You may also like

发表评论

电子邮件地址不会被公开。 必填项已用*标注