【问题标题】:WMI Query to get list of Service PacksWMI 查询以获取服务包列表
【发布时间】:2009-06-12 14:10:56
【问题描述】:

是否可以使用 WMI 找出安装在 Windows 2000 机器上的服务包?

【问题讨论】:

    标签: wmi windows-server-2000 wmi-query


    【解决方案1】:

    有一种使用 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
    

    【讨论】:

      【解决方案2】:

      是的,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 来检查远程系统。

      【讨论】:

        【解决方案3】:

        Hey, Scripting Guy! 系列的 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
        

        【讨论】:

          猜你喜欢
          • 2018-11-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-02-08
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多