[英]Return key path from Registry Using Powershell
I am writing a script that will be able to erase entries from the registry. 我正在编写一个脚本,该脚本将能够从注册表中删除条目。 The problem is that the endpoint in:
HKCU:\\Software\\Microsoft\\Windows\\ CurrentVersion\\Uninstall\\{NUMBER}
is not constant and changes each time the product is installed. 问题在于,
HKCU:\\Software\\Microsoft\\Windows\\ CurrentVersion\\Uninstall\\{NUMBER}
中的端点不是恒定的,并且每次安装产品时都会更改。 I found a similar solution to the problem here , and changed the script to myself. 我在这里找到了类似的解决方案,并将脚本更改为我自己。 But I still do not know how to delete exactly what is in the {NUMBER} folder .
但是我仍然不知道如何准确删除{NUMBER}文件夹中的内容。
At this time, the script can return only Publisher,DisplayName,DisplayVersion,UninstallString
but resolves the problem so that the script returns the full path, or at least the name of the folder where these records are located? 此时,脚本只能返回
Publisher,DisplayName,DisplayVersion,UninstallString
但可以解决问题,以便脚本返回完整路径,或者至少返回这些记录所在的文件夹的名称? And would the best to be removed? 最好将其删除吗?
Here is my code: 这是我的代码:
$PATHS = @("HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\")
$SOFTWARE = "APPLICATION"
ForEach ($path in $PATHS) {
$installed = Get-ChildItem -Path $path |
ForEach { Get-ItemProperty $_.PSPath } |
Where-Object { $_.DisplayName -match $SOFTWARE } |
Select-Object -Property Publisher,DisplayName,DisplayVersion,UninstallString
ForEach ($app in $installed) {
Write-Output "$($app.DisplayName)"
}
}
You didn't mention the PowerShell version, I assume it's PowerShell 5.1 running on Windows 10, wish it help: 您没有提到PowerShell版本,我假设它是Windows 10上运行的PowerShell 5.1,希望对您有所帮助:
Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"
I think you can find whatever you want from the result: 我认为您可以从结果中找到想要的任何东西:
PSChildName
: the {number} you mentioned PSChildName
:您提到的{number}
InstallLocation
: the folder where insatlled InstallLocation
:安装位置的文件夹
As to display name
, display version
, publisher
, etc, just pick the field. 至于
display name
, display version
, publisher
等,只需选择该字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.