Multiple App uninstall in Mod Template/Functions

pull/257/head
GAJ-san 2023-01-05 15:37:30 +01:00
parent 53113310c0
commit 91e788ebb5
2 changed files with 68 additions and 65 deletions

View File

@ -6,8 +6,8 @@ $Proc = @("")
$Wait = @("")
#Beginning of App Name string to Silently Uninstall (MSI/NSIS/INNO/EXE with defined silent uninstall in registry)
#Required wildcard (*) after, search is done with "-like"!
$App = ""
#Multiple: "app1*","app2*", required wildcard (*) after; search is done with "-like"!
$App = @("")
#Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2"
$Lnk = @("")

View File

@ -15,63 +15,9 @@ function Wait-ModsProc ($Wait) {
Return
}
function Uninstall-ModsApp ($App) {
$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ($obj in $InstalledSoftware){
if ($obj.GetValue('DisplayName') -like $App) {
$UninstallString = $obj.GetValue('UninstallString')
$CleanedUninstallString = $UninstallString.Trim([char]0x0022)
if ($UninstallString -like "MsiExec.exe*") {
$ProductCode = Select-String "{.*}" -inputobject $UninstallString
$ProductCode = $ProductCode.matches.groups[0].value
#MSI x64 Installer
$Exec = Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/x$ProductCode REBOOT=R /qn" -PassThru -Wait
#Stop Hard Reboot (if bad MSI!)
if ($Exec.ExitCode -eq 1641) {
Start-Process "C:\Windows\System32\shutdown.exe" -ArgumentList "/a"
}
}
else {
$QuietUninstallString = $obj.GetValue('QuietUninstallString')
if ($QuietUninstallString) {
$QuietUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $QuietUninstallString
$Command = $QuietUninstallString.matches.groups[1].value
$Parameter = $QuietUninstallString.matches.groups[2].value
#All EXE x64 Installers (already defined silent uninstall)
Start-Process $Command -ArgumentList $Parameter -Wait
}
else {
if ((Test-Path $CleanedUninstallString)) {
$NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft"
}
if ($NullSoft) {
#NSIS x64 Installer
Start-Process $UninstallString -ArgumentList "/S" -Wait
}
else {
if ((Test-Path $CleanedUninstallString)) {
$Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup"
}
if ($Inno) {
#Inno x64 Installer
Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait
}
else {
Write-Host "x64 Uninstaller unknown, trying the UninstallString from registry..."
$NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString
$Command = $NativeUninstallString.matches.groups[1].value
$Parameter = $NativeUninstallString.matches.groups[2].value
#All EXE x64 Installers (native defined uninstall)
Start-Process $Command -ArgumentList $Parameter -Wait
}
}
}
}
$x64 = $true
break
}
}
if (!$x64) {
$InstalledSoftware = Get-ChildItem "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ($process in $Proc)
{
$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ($obj in $InstalledSoftware){
if ($obj.GetValue('DisplayName') -like $App) {
$UninstallString = $obj.GetValue('UninstallString')
@ -79,7 +25,7 @@ function Uninstall-ModsApp ($App) {
if ($UninstallString -like "MsiExec.exe*") {
$ProductCode = Select-String "{.*}" -inputobject $UninstallString
$ProductCode = $ProductCode.matches.groups[0].value
#MSI x86 Installer
#MSI x64 Installer
$Exec = Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/x$ProductCode REBOOT=R /qn" -PassThru -Wait
#Stop Hard Reboot (if bad MSI!)
if ($Exec.ExitCode -eq 1641) {
@ -92,7 +38,7 @@ function Uninstall-ModsApp ($App) {
$QuietUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $QuietUninstallString
$Command = $QuietUninstallString.matches.groups[1].value
$Parameter = $QuietUninstallString.matches.groups[2].value
#All EXE x86 Installers (already defined silent uninstall)
#All EXE x64 Installers (already defined silent uninstall)
Start-Process $Command -ArgumentList $Parameter -Wait
}
else {
@ -100,7 +46,7 @@ function Uninstall-ModsApp ($App) {
$NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft"
}
if ($NullSoft) {
#NSIS x86 Installer
#NSIS x64 Installer
Start-Process $UninstallString -ArgumentList "/S" -Wait
}
else {
@ -108,23 +54,80 @@ function Uninstall-ModsApp ($App) {
$Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup"
}
if ($Inno) {
#Inno x86 Installer
#Inno x64 Installer
Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait
}
else {
Write-Host "x86 Uninstaller unknown, trying the UninstallString from registry..."
Write-Host "x64 Uninstaller unknown, trying the UninstallString from registry..."
$NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString
$Command = $NativeUninstallString.matches.groups[1].value
$Parameter = $NativeUninstallString.matches.groups[2].value
#All EXE x86 Installers (native defined uninstall)
#All EXE x64 Installers (native defined uninstall)
Start-Process $Command -ArgumentList $Parameter -Wait
}
}
}
}
$x64 = $true
break
}
}
if (!$x64) {
$InstalledSoftware = Get-ChildItem "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ($obj in $InstalledSoftware){
if ($obj.GetValue('DisplayName') -like $App) {
$UninstallString = $obj.GetValue('UninstallString')
$CleanedUninstallString = $UninstallString.Trim([char]0x0022)
if ($UninstallString -like "MsiExec.exe*") {
$ProductCode = Select-String "{.*}" -inputobject $UninstallString
$ProductCode = $ProductCode.matches.groups[0].value
#MSI x86 Installer
$Exec = Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/x$ProductCode REBOOT=R /qn" -PassThru -Wait
#Stop Hard Reboot (if bad MSI!)
if ($Exec.ExitCode -eq 1641) {
Start-Process "C:\Windows\System32\shutdown.exe" -ArgumentList "/a"
}
}
else {
$QuietUninstallString = $obj.GetValue('QuietUninstallString')
if ($QuietUninstallString) {
$QuietUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $QuietUninstallString
$Command = $QuietUninstallString.matches.groups[1].value
$Parameter = $QuietUninstallString.matches.groups[2].value
#All EXE x86 Installers (already defined silent uninstall)
Start-Process $Command -ArgumentList $Parameter -Wait
}
else {
if ((Test-Path $CleanedUninstallString)) {
$NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft"
}
if ($NullSoft) {
#NSIS x86 Installer
Start-Process $UninstallString -ArgumentList "/S" -Wait
}
else {
if ((Test-Path $CleanedUninstallString)) {
$Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup"
}
if ($Inno) {
#Inno x86 Installer
Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait
}
else {
Write-Host "x86 Uninstaller unknown, trying the UninstallString from registry..."
$NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString
$Command = $NativeUninstallString.matches.groups[1].value
$Parameter = $NativeUninstallString.matches.groups[2].value
#All EXE x86 Installers (native defined uninstall)
Start-Process $Command -ArgumentList $Parameter -Wait
}
}
}
}
break
}
}
}
}
Return
}