Multiple App uninstall in Mod Template/Functions
parent
53113310c0
commit
91e788ebb5
|
@ -6,8 +6,8 @@ $Proc = @("")
|
||||||
$Wait = @("")
|
$Wait = @("")
|
||||||
|
|
||||||
#Beginning of App Name string to Silently Uninstall (MSI/NSIS/INNO/EXE with defined silent uninstall in registry)
|
#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"!
|
#Multiple: "app1*","app2*", required wildcard (*) after; search is done with "-like"!
|
||||||
$App = ""
|
$App = @("")
|
||||||
|
|
||||||
#Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2"
|
#Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2"
|
||||||
$Lnk = @("")
|
$Lnk = @("")
|
||||||
|
|
|
@ -15,63 +15,9 @@ function Wait-ModsProc ($Wait) {
|
||||||
Return
|
Return
|
||||||
}
|
}
|
||||||
function Uninstall-ModsApp ($App) {
|
function Uninstall-ModsApp ($App) {
|
||||||
$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
|
foreach ($process in $Proc)
|
||||||
foreach ($obj in $InstalledSoftware){
|
{
|
||||||
if ($obj.GetValue('DisplayName') -like $App) {
|
$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
|
||||||
$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 ($obj in $InstalledSoftware){
|
foreach ($obj in $InstalledSoftware){
|
||||||
if ($obj.GetValue('DisplayName') -like $App) {
|
if ($obj.GetValue('DisplayName') -like $App) {
|
||||||
$UninstallString = $obj.GetValue('UninstallString')
|
$UninstallString = $obj.GetValue('UninstallString')
|
||||||
|
@ -79,7 +25,7 @@ function Uninstall-ModsApp ($App) {
|
||||||
if ($UninstallString -like "MsiExec.exe*") {
|
if ($UninstallString -like "MsiExec.exe*") {
|
||||||
$ProductCode = Select-String "{.*}" -inputobject $UninstallString
|
$ProductCode = Select-String "{.*}" -inputobject $UninstallString
|
||||||
$ProductCode = $ProductCode.matches.groups[0].value
|
$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
|
$Exec = Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/x$ProductCode REBOOT=R /qn" -PassThru -Wait
|
||||||
#Stop Hard Reboot (if bad MSI!)
|
#Stop Hard Reboot (if bad MSI!)
|
||||||
if ($Exec.ExitCode -eq 1641) {
|
if ($Exec.ExitCode -eq 1641) {
|
||||||
|
@ -92,7 +38,7 @@ function Uninstall-ModsApp ($App) {
|
||||||
$QuietUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $QuietUninstallString
|
$QuietUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $QuietUninstallString
|
||||||
$Command = $QuietUninstallString.matches.groups[1].value
|
$Command = $QuietUninstallString.matches.groups[1].value
|
||||||
$Parameter = $QuietUninstallString.matches.groups[2].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
|
Start-Process $Command -ArgumentList $Parameter -Wait
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -100,7 +46,7 @@ function Uninstall-ModsApp ($App) {
|
||||||
$NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft"
|
$NullSoft = Select-String -Path $CleanedUninstallString -Pattern "Nullsoft"
|
||||||
}
|
}
|
||||||
if ($NullSoft) {
|
if ($NullSoft) {
|
||||||
#NSIS x86 Installer
|
#NSIS x64 Installer
|
||||||
Start-Process $UninstallString -ArgumentList "/S" -Wait
|
Start-Process $UninstallString -ArgumentList "/S" -Wait
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -108,23 +54,80 @@ function Uninstall-ModsApp ($App) {
|
||||||
$Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup"
|
$Inno = Select-String -Path $CleanedUninstallString -Pattern "Inno Setup"
|
||||||
}
|
}
|
||||||
if ($Inno) {
|
if ($Inno) {
|
||||||
#Inno x86 Installer
|
#Inno x64 Installer
|
||||||
Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait
|
Start-Process $UninstallString -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait
|
||||||
}
|
}
|
||||||
else {
|
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
|
$NativeUninstallString = Select-String "(\x22.*\x22) +(.*)" -inputobject $UninstallString
|
||||||
$Command = $NativeUninstallString.matches.groups[1].value
|
$Command = $NativeUninstallString.matches.groups[1].value
|
||||||
$Parameter = $NativeUninstallString.matches.groups[2].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
|
Start-Process $Command -ArgumentList $Parameter -Wait
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$x64 = $true
|
||||||
break
|
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
|
Return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue