在cmd中,wmic命令查询注册表路径:
HKEY_CLASSES_ROOT\Installer\Products
但此程序列表仅限于使用 MSI 安装的程序。
我想创建一个批处理脚本来卸载出现在 appwiz.cpl(程序和功能)中的应用程序,我相信该脚本存储在不同的注册表路径中(我相信还有更多,但需要进一步挖掘):
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
所以我的问题是,如何从仅限于 MSI 安装的软件的路径之外的路径卸载应用程序,类似于 wmic 使用 cmd 执行的操作?
答案1
你必须在你提到的每个文件夹中进行搜索
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
查找名为 UninstallString 的值并运行该值的数据中包含的程序,该程序包含卸载程序的路径......
答案2
您可以尝试使用类似以下代码的 PowerShell 脚本:
$ErrorActionPreference = 'Stop'
$InstalledApplications = "$Env:userprofile\desktop\InstalledApplications.txt"
if (Test-Path $InstalledApplications) {Remove-Item $InstalledApplications}
$Error_Log = "$Env:userprofile\desktop\Error_Log.txt"
function Get-InstalledApplications {
try {
$registry32 = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
$applications32 = Get-ItemProperty $registry32\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$applications32 | Out-File -FilePath $InstalledApplications -Encoding UTF8 -Append
$applications32 | Format-Table
} catch {
# Code to handle the exception
$ErrorMessage = $_.Exception.Message
$Timestamp = (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
$ErrorLine = $_.InvocationInfo.ScriptLineNumber
$ErrorDetails = "$Timestamp - Error occurred in Get-InstalledApplications function at line: $ErrorLine. Error Message: $ErrorMessage"
Add-Content -Path $Error_Log -Value $ErrorDetails -ErrorAction 'Continue'
}
try {
$registry64 = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$applications64 = Get-ItemProperty $registry64\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$applications64 | Out-File -FilePath $InstalledApplications -Encoding UTF8 -Append
$applications64 | Format-Table
} catch {
# Code to handle the exception
$ErrorMessage = $_.Exception.Message
$Timestamp = (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
$ErrorLine = $_.InvocationInfo.ScriptLineNumber
$ErrorDetails = "$Timestamp - Error occurred in Get-InstalledApplications function at line: $ErrorLine. Error Message: $ErrorMessage"
Add-Content -Path $Error_Log -Value $ErrorDetails -ErrorAction 'Continue'
}
}
Get-InstalledApplications
if (Test-Path $InstalledApplications) {ii $InstalledApplications}