🎃
アプリをアンインストールするためのPowershellスクリプト
$appName = "aws-cfn-bootstrap"
$keyPaths = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
foreach ($path in $keyPaths) {
$apps = Get-ItemProperty $path | Where-Object { $_.DisplayName -like "*$appName*" }
foreach ($app in $apps) {
if ($app.UninstallString) {
$uninstallCmd = $app.UninstallString
# アンインストーラの形式ごとにサイレントオプションを付与
if ($uninstallCmd -match "msiexec\.exe") {
# 例: msiexec /x {GUID}
$uninstallCmd += " /quiet /norestart"
} elseif ($uninstallCmd -notmatch "/quiet") {
# .exeタイプなどで /quiet を持っていない場合に追加
$uninstallCmd += " /quiet"
}
Write-Host "実行: $uninstallCmd"
Start-Process -FilePath "cmd.exe" -ArgumentList "/c $uninstallCmd" -Wait
}
}
}
Discussion