WMI “installed” query different from add/remove programs list?

后端 未结 13 1899
不知归路
不知归路 2020-11-29 01:56

Trying to use WMI to obtain a list of installed programs for Windows XP. Using wmic, I tried:

wmic /output:c:\\ProgramList.txt product get name,version
         


        
13条回答
  •  眼角桃花
    2020-11-29 02:41

    Hope this helps somebody: I've been using the registry-based enumeration in my scripts (as suggested by some of the answers above), but have found that it does not properly enumerate 64-bit software when run on Windows 10 x64 via SCCM (which uses a 32-bit client). Found something like this to be the most straightforward solution in my particular case:

    Function Get-Programs($Bits) {
      $Result = @()
      $Output = (reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall /reg:$Bits /s)
    
      Foreach ($Line in $Output) {
        If ($Line -match '^\s+DisplayName\s+REG_SZ\s+(.+?)$') {
          $Result += New-Object PSObject -Property @{
            DisplayName = $matches[1];
            Bits = "$($Bits)-bit";
          }
        }
      }
    
      $Result
    }
    
    $Software  = Get-Programs 32
    $Software += Get-Programs 64
    

    Realize this is a little too Perl-ish in a bad way, but all other alternatives I've seen involved insanity with wrapper scripts and similar clever-clever solutions, and this seems a little more human.

    P.S. Trying really hard to refrain from dumping a ton of salt on Microsoft here for making an absolutely trivial thing next to impossible. I.e., enumerating all MS Office versions in use on a network is a task to make a grown man weep.

提交回复
热议问题