WMI 查询以获取服务包列表

发布于 2024-07-25 00:41:49 字数 45 浏览 7 评论 0原文

是否可以使用 WMI 查找 Windows 2000 计算机上安装的服务包?

Is it possible to find out the service packs that are installed on a Windows 2000 machine using WMI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

相对绾红妆 2024-08-01 00:41:49

有一种使用 WMI 获取已安装软件的建议方法 - 尽管并非所有软件都会显示,因此您必须...

1) 尝试一下,看看它们是否完全出现

2) 调整示例以过滤结果,以便仅服务包显示

strHost = "."
Const HKLM = &H80000002
Set objReg = GetObject("winmgmts://" & strHost & _
    "/root/default:StdRegProv")
Const strBaseKey = _
    "Software\Microsoft\Windows\CurrentVersion\Uninstall\"
objReg.EnumKey HKLM, strBaseKey, arrSubKeys
For Each strSubKey In arrSubKeys
    intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _
        "DisplayName", strValue)
    If intRet <> 0 Then
        intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _
        "QuietDisplayName", strValue)
    End If
    If (strValue <> "") and (intRet = 0) Then
        WScript.Echo strValue
    End If
Next

There's a suggested way of getting installed software using WMI - although not all software shows up, so you'd have to...

1) Try it out and see if they appear at all

2) Adjust the example to filter the results so only service packs show

strHost = "."
Const HKLM = &H80000002
Set objReg = GetObject("winmgmts://" & strHost & _
    "/root/default:StdRegProv")
Const strBaseKey = _
    "Software\Microsoft\Windows\CurrentVersion\Uninstall\"
objReg.EnumKey HKLM, strBaseKey, arrSubKeys
For Each strSubKey In arrSubKeys
    intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _
        "DisplayName", strValue)
    If intRet <> 0 Then
        intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _
        "QuietDisplayName", strValue)
    End If
    If (strValue <> "") and (intRet = 0) Then
        WScript.Echo strValue
    End If
Next
吃素的狼 2024-08-01 00:41:49

是的,wmi 类 Win32_OperatingSystem 包含所有这些信息。 我可以通过使用 powershell 检查本地计算机来验证此信息:

PS c:\> get-wmiobject win32_operatingsystem | `
            select BuildNumber, ServicePackMajorVersion, `
            ServicePackMinorVersion | format-table -auto

BuildNumber ServicePackMajorVersion ServicePackMinorVersion
----------- ----------------------- -----------------------
7100                              0                       0

注意:Powershell 仅在 XP 或更高版本上运行,但您可以通过将 -Computer 参数传递给 get-wmiobject 来检查远程系统。

Yes, the wmi class Win32_OperatingSystem contains all of this information. I can see verify this information by using powershell to check my local machine:

PS c:\> get-wmiobject win32_operatingsystem | `
            select BuildNumber, ServicePackMajorVersion, `
            ServicePackMinorVersion | format-table -auto

BuildNumber ServicePackMajorVersion ServicePackMinorVersion
----------- ----------------------- -----------------------
7100                              0                       0

Note: Powershell only runs on XP or higher, but you can check remote systems by passing a -Computer parameter to get-wmiobject.

心安伴我暖 2024-08-01 00:41:49

嘿,脚本专家! 系列中的 VBScript 示例:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo objOperatingSystem.ServicePackMajorVersion  _
        & "." & objOperatingSystem.ServicePackMinorVersion
Next

A VBScript example from Hey, Scripting Guy! series:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo objOperatingSystem.ServicePackMajorVersion  _
        & "." & objOperatingSystem.ServicePackMinorVersion
Next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文