使用Powershell从注册表中获取C ++ 2008的产品代码

问题描述 投票:1回答:2

我试图获取我的设备上安装的所有Visual C ++ 2008的产品代码并编写下面的代码,但我被卡住了。代码执行但不执行任何操作。请协助。

$log      = "C:\VC2008.log"
$regkey = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-Object DisplayName)
$RegKey.PSObject.Properties |  ForEach-Object {
    If($_.Name -like '*DisplayName*')
    {
        If ($_.value -like 'Microsoft Visual C++ 2008')
        {
            "$date [INFO]`t $regkey.PSChildname found in Registry !!! " | Out-File $log -append
        }

    }
} 
powershell visual-c++-2008
2个回答
1
投票

因此,您正在错误地检索您的值并使事情过于复杂。

工作方案:

$Log    = 'C:\VC2008.log'
$RegKey = Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
     Where-Object { $_.DisplayName -like '*Microsoft Visual C++ 2008*' }
If ($RegKey)
{
    "$(Get-Date) [INFO]`t $($RegKey.PSChildName) found in registry!" |
        Out-File -FilePath $Log -Append
}

输出:

12/20/2017 11:12:51 AM [INFO] {8220EEFE-38CD-377E-8595-13398D740ACE}在注册表中找到了!

测试键:

AuthorizedCDFPrefix :
Comments            :
Contact             :
DisplayVersion      : 9.0.30729
HelpLink            :
HelpTelephone       :
InstallDate         : 20170901
InstallLocation     :
InstallSource       : c:\14a5eb4f904aafee464a2e0ecc\
ModifyPath          : MsiExec.exe /X{8220EEFE-38CD-377E-8595-13398D740ACE}
NoModify            : 1
NoRepair            : 1
Publisher           : Microsoft Corporation
Readme              :
Size                :
EstimatedSize       : 1136
UninstallString     : MsiExec.exe /X{8220EEFE-38CD-377E-8595-13398D740ACE}
URLInfoAbout        :
URLUpdateInfo       :
VersionMajor        : 9
VersionMinor        : 0
WindowsInstaller    : 1
Version             : 151025673
Language            : 1033
DisplayName         : Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.17
sEstimatedSize2     : 13596
PSPath              : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\{8220EEFE-38CD-377E-8595-13398D740ACE}
PSParentPath        : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
PSChildName         : {8220EEFE-38CD-377E-8595-13398D740ACE}
PSProvider          : Microsoft.PowerShell.Core\Registry

0
投票

这应该为您提供您想要的价值:

    (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* ).displayname | Where-object{$_ -like 'Microsoft visual c++ 2008*'}
© www.soinside.com 2019 - 2024. All rights reserved.