首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >64位等价的WMI类"win32reg_addremoveprograms"?

64位等价的WMI类"win32reg_addremoveprograms"?
EN

Stack Overflow用户
提问于 2010-03-10 19:01:27
回答 1查看 8.7K关注 0票数 5

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

代码语言:javascript
复制
$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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-03-10 22:08:37

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

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

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2416278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档