如何检查是否已从c#安装Windows QFE /修补程序?

如何检查是否已从c#安装Windows QFE /修补程序?

How do I check that a Windows QFE/patch has been installed from c#?

在C#中确定已安装给定QFE /补丁的最佳方法是什么?


使用WMI并检查Win32_QuickFixEngineering枚举。

从TechNet:

1
2
3
4
5
6
7
8
9
10
11
12
13
strComputer ="."
Set objWMIService = GetObject("winmgmts:" _
    &"{impersonationLevel=impersonate}!\\\" & strComputer &"\
oot\\cimv2")
Set colQuickFixes = objWMIService.ExecQuery _
    ("
Select * from Win32_QuickFixEngineering")
For Each objQuickFix in colQuickFixes
    Wscript.Echo"
Computer:" & objQuickFix.CSName
    Wscript.Echo"
Description:" & objQuickFix.Description
    Wscript.Echo"
Hot Fix ID:" & objQuickFix.HotFixID
    Wscript.Echo"
Installation Date:" & objQuickFix.InstallDate
    Wscript.Echo"
Installed By:" & objQuickFix.InstalledBy
Next

HotFixID是您要检查的内容。

这是我系统上的输出:

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
    Hot Fix ID: KB941569
    Description: Security Update for Windows XP (KB941569)
    Hot Fix ID: KB937143-IE7
    Description: Security Update for Windows Internet Explorer 7 (KB937143)
    Hot Fix ID: KB938127-IE7
    Description: Security Update for Windows Internet Explorer 7 (KB938127)
    Hot Fix ID: KB939653-IE7
    Description: Security Update for Windows Internet Explorer 7 (KB939653)
    Hot Fix ID: KB942615-IE7
    Description: Security Update for Windows Internet Explorer 7 (KB942615)
    Hot Fix ID: KB944533-IE7
    Description: Security Update for Windows Internet Explorer 7 (KB944533)
    Hot Fix ID: KB947864-IE7
    Description: Hotfix for Windows Internet Explorer 7 (KB947864)
    Hot Fix ID: KB950759-IE7
    Description: Security Update for Windows Internet Explorer 7 (KB950759)
    Hot Fix ID: KB953838-IE7
    Description: Security Update for Windows Internet Explorer 7 (KB953838)
    Hot Fix ID: MSCompPackV1
    Description: Microsoft Compression Client Pack 1.0 for Windows XP
    Hot Fix ID: KB873339
    Description: Windows XP Hotfix - KB873339
    Hot Fix ID: KB885835
    Description: Windows XP Hotfix - KB885835
    Hot Fix ID: KB885836
    Description: Windows XP Hotfix - KB885836
    Hot Fix ID: KB886185
    Description: Windows XP Hotfix - KB886185
    Hot Fix ID: KB887472
    Description: Windows XP Hotfix - KB887472
    Hot Fix ID: KB888302
    Description: Windows XP Hotfix - KB888302
    Hot Fix ID: KB890046
    Description: Security Update for Windows XP (KB890046)

最可靠的方法是确定哪些文件受QFE影响,并在每个文件上使用System.Diagnostics.FileVersionInfo.GetVersionInfo(path)并比较版本号。

编辑:我认为也有一种方法可以检查注册表中的卸载信息,但是如果QFE曾经成为Service Pack或汇总包的一部分,则可能会报告错误的否定信息


推荐阅读