【问题标题】:64bit equivalent class for a wmi class "win32reg_addremoveprograms"?wmi 类“win32reg_addremoveprograms”的 64 位等效类?
【发布时间】:2010-03-10 11:01:27
【问题描述】:

我下面的代码在 32 位 Windows 机器上完美运行,但是由于代码中使用了 32 位 WMI 类 win32reg_addremoveprograms,它拒绝在 64 位机器上运行。有这个类的 64 位等价物吗?

$ServerFile = "D:\SharePoint\Powershell\AddRemovePrograms\Machines.txt"
$ServerList = Get-Content $ServerFile

$Excel = New-Object -Com Excel.Application
$Excel.displayalerts=$False
$Excel.visible = $True

$workbook = $Excel.Workbooks.Add()
$workbook.workSheets.item(2).delete()
$workbook.WorkSheets.item(2).delete()

$Sheet = $workbook.WorkSheets.Item(1)
$Sheet.Name= "Program List";

$intRow = 1

foreach ($NextServer in $ServerList)
{
    $Sheet.Cells.Item($intRow,1) = “Computer Name”
    $Sheet.Cells.Item($intRow,2) = $NextServer

    $Sheet.Cells.Item($intRow,1).Interior.ColorIndex = 8
    $Sheet.Cells.Item($intRow,1).Font.ColorIndex = 11
    $Sheet.Cells.Item($intRow,1).Font.Bold = $True
    $Sheet.Cells.Item($intRow,2).Interior.ColorIndex = 8
    $Sheet.Cells.Item($intRow,2).Font.ColorIndex = 11
    $Sheet.Cells.Item($intRow,2).Font.Bold = $True

    $intRow = $intRow + 2
    $Sheet.Cells.Item($intRow,1) = "Programs"
    $Sheet.Cells.Item($intRow,1).Interior.ColorIndex = 12
    $Sheet.Cells.Item($intRow,1).Font.ColorIndex = 8
    $Sheet.Cells.Item($intRow,1).Font.Bold = $True
    $intRow = $intRow + 1

    $colItems =get-wmiobject -class "win32reg_addremoveprograms" -computername $NextServer  |  select-object -property DisplayName | sort-object  DisplayName

    foreach ($objItem in $colItems)
    {
        if ($objItem.DisplayName.IndexOf('Update') -eq -1 -and $objItem.DisplayName.IndexOf('2007 Microsoft Office') -eq -1)
        {   
            $Sheet.Cells.Item($intRow,1) = $objItem.DisplayName
            $intRow = $intRow + 1
        }
    }
    $intRow = $intRow + 2
}

$workArea = $Sheet.UsedRange
$workArea.EntireColumn.AutoFit()
$workbook.SaveAs("D:\SharePoint\Powershell\AddRemovePrograms\Programs.xls")
$workbook.close() 
$a = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($workArea)
$a = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Sheet)
$a = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($workbook)
$Excel.Quit()
$a = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Excel)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers() 
Remove-Variable Excel, intRow ,workbook, Sheet,colItems, ServerFile, ServerList, a

【问题讨论】:

    标签: windows-7 powershell wmi


    【解决方案1】:

    您的 64 位计算机上是否安装了 SCCM/SMS 客户端?因为Win32Reg_AddRemovePrograms WMI 类是由 SCCM/SMS 客户端添加的,因此如果您没有安装它就无法使用。

    另请注意,Win32Reg_AddRemovePrograms 仅提供有关 32 位已安装应用程序的信息。要获取有关 64 位应用程序的信息,请使用 Win32Reg_AddRemovePrograms64 类(在 SMS 2003 SP3 及更高版本中可用)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-17
      • 1970-01-01
      • 2011-06-09
      • 1970-01-01
      • 2019-07-19
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多