#Requires -RunAsAdministrator <# .SYNOPSIS Nerdy Neighbor - Silent Malwarebytes uninstaller (no downloads). .NOTES Run with: irm mbam-uninstall.nerdyneighbor.net | iex (elevated Windows PowerShell) Uses Malwarebytes' OWN built-in uninstaller that already lives on the machine (mbuns.exe) - nothing is downloaded. The /NOSURVEY switch skips the annoying exit survey. Then it sweeps any residual folders and verifies. 1. Locate the built-in uninstaller (known path + registry UninstallString). 2. Run it silently: mbuns.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /NOSURVEY 3. Wait for the product to actually disappear, then sweep leftovers. No reboot is forced. Logs to C:\ProgramData\NerdyNeighbor\mbam-uninstall.log Exit code 0 = gone, 1 = still present / failed. #> $ErrorActionPreference = 'Stop' # --- Constants --------------------------------------------------------------- $MbunsArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /NOSURVEY' $LogDir = Join-Path $env:ProgramData 'NerdyNeighbor' $LogFile = Join-Path $LogDir 'mbam-uninstall.log' $ResidualPaths = @( (Join-Path $env:ProgramFiles 'Malwarebytes'), (Join-Path ${env:ProgramFiles(x86)} 'Malwarebytes'), (Join-Path $env:ProgramData 'Malwarebytes') ) $UninstallKeys = @( 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' ) # --- Logging ----------------------------------------------------------------- if (-not (Test-Path $LogDir)) { New-Item -ItemType Directory -Path $LogDir -Force | Out-Null } function Write-Log { param([string]$Message, [string]$Level = 'INFO') $line = '{0} [{1}] {2}' -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $Level, $Message Add-Content -Path $LogFile -Value $line -ErrorAction SilentlyContinue switch ($Level) { 'ERROR' { Write-Host " $Message" -ForegroundColor Red } 'WARN' { Write-Host " $Message" -ForegroundColor Yellow } default { Write-Host " $Message" -ForegroundColor Gray } } } function Test-MalwarebytesPresent { if (Test-Path "$env:ProgramFiles\Malwarebytes\Anti-Malware\mbam.exe") { return $true } if (Test-Path "${env:ProgramFiles(x86)}\Malwarebytes\Anti-Malware\mbam.exe") { return $true } if (Get-Service -Name 'MBAMService' -ErrorAction SilentlyContinue) { return $true } if (Get-MbunsExe) { return $true } foreach ($p in $ResidualPaths) { if ($p -and (Test-Path $p)) { return $true } } return $false } # Find the built-in uninstaller executable, preferring the known install path # and falling back to whatever the registry records for "Malwarebytes". function Get-MbunsExe { $candidates = @( "$env:ProgramFiles\Malwarebytes\Anti-Malware\mbuns.exe", "${env:ProgramFiles(x86)}\Malwarebytes\Anti-Malware\mbuns.exe" ) foreach ($c in $candidates) { if ($c -and (Test-Path $c)) { return $c } } foreach ($key in $UninstallKeys) { Get-ItemProperty -Path $key -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -like '*Malwarebytes*' } | ForEach-Object { $s = $_.QuietUninstallString; if (-not $s) { $s = $_.UninstallString } if ($s) { # Strip quotes/args to get the bare .exe path. if ($s -match '"([^"]+\.exe)"') { $exe = $matches[1] } elseif ($s -match '([A-Za-z]:\\[^"]+?\.exe)') { $exe = $matches[1] } else { $exe = $null } if ($exe -and (Test-Path $exe)) { return $exe } } } } return $null } # --- Main -------------------------------------------------------------------- try { Write-Host "" Write-Host " Nerdy Neighbor - Malwarebytes uninstaller" -ForegroundColor Cyan Write-Host "" Write-Log "=== Uninstall run started on $env:COMPUTERNAME (user: $env:USERNAME) ===" if (-not (Test-MalwarebytesPresent)) { Write-Host "" Write-Log "Malwarebytes was not detected on this machine - nothing to remove." 'INFO' Write-Host " Nothing to do - Malwarebytes is not installed." -ForegroundColor Green Write-Host "" exit 0 } # --- Run the built-in uninstaller --------------------------------------- $mbuns = Get-MbunsExe if ($mbuns) { Write-Log "Found built-in uninstaller: $mbuns" Write-Log "Running it silently (survey suppressed)..." try { $p = Start-Process -FilePath $mbuns -ArgumentList $MbunsArgs -Wait -PassThru Write-Log "Uninstaller process exited with code $($p.ExitCode)." } catch { Write-Log "Uninstaller failed to launch: $($_.Exception.Message)" 'WARN' } # Inno uninstallers often return before the work is finished - poll for # the product to actually go away (up to ~2 minutes). Write-Log "Waiting for Malwarebytes to finish removing itself..." $waited = 0 while ($waited -lt 120 -and ( (Test-Path "$env:ProgramFiles\Malwarebytes\Anti-Malware\mbam.exe") -or (Get-Service -Name 'MBAMService' -ErrorAction SilentlyContinue) )) { Start-Sleep -Seconds 5 $waited += 5 } Write-Log "Waited ${waited}s for the uninstaller to complete." } else { Write-Log "Could not locate the built-in uninstaller (mbuns.exe) - will only sweep leftover folders." 'WARN' } # --- Residual folder sweep ---------------------------------------------- Write-Log "Sweeping any residual Malwarebytes folders..." foreach ($path in $ResidualPaths) { if ($path -and (Test-Path $path)) { try { Remove-Item -LiteralPath $path -Recurse -Force -ErrorAction Stop Write-Log "Removed leftover folder: $path" } catch { Write-Log "Could not remove $path ($($_.Exception.Message)) - may need a reboot to release locks." 'WARN' } } } # --- Verify -------------------------------------------------------------- if (Test-MalwarebytesPresent) { Write-Log "Malwarebytes traces still present after uninstall - a reboot then re-run may be required." 'WARN' Write-Host "" Write-Host " Partly removed - some traces remain. Reboot and re-run to finish." -ForegroundColor Yellow Write-Host " Log: $LogFile" -ForegroundColor Gray Write-Host "" exit 1 } Write-Host "" Write-Log "Malwarebytes uninstalled - no traces detected." 'INFO' Write-Host " Done. Malwarebytes has been removed." -ForegroundColor Green Write-Host "" exit 0 } catch { Write-Log "FAILED: $($_.Exception.Message)" 'ERROR' if ($_.InvocationInfo.ScriptLineNumber) { Write-Log ("At line {0}: {1}" -f $_.InvocationInfo.ScriptLineNumber, $_.InvocationInfo.Line.Trim()) 'ERROR' } Write-Host "" Write-Host " Uninstall failed. Full log: $LogFile" -ForegroundColor Yellow Write-Host "" exit 1 }