2 Commits
main ... main

385
remove-office.ps1 Normal file
View File

@@ -0,0 +1,385 @@
# OfficeCleaner.ps1
# Script para limpiar instalaciones problemáticas de Microsoft Office
# Autor: Asistente de PowerShell
# Repositorio: [Nombre de tu repositorio]
# ============================================
# CONFIGURACIÓN Y DECLARACIONES
# ============================================
# Versión del script
$ScriptVersion = "1.2.0"
# Colores para mensajes
$ColorSuccess = "Green"
$ColorWarning = "Yellow"
$ColorError = "Red"
$ColorInfo = "Cyan"
# ============================================
# FUNCIONES PRINCIPALES
# ============================================
function Show-Header {
Clear-Host
Write-Host "=============================================" -ForegroundColor $ColorInfo
Write-Host " OFFICE CLEANER - LIMPIADOR DE OFFICE" -ForegroundColor $ColorInfo
Write-Host " Versión $ScriptVersion" -ForegroundColor $ColorInfo
Write-Host "=============================================" -ForegroundColor $ColorInfo
Write-Host ""
}
function Test-Administrator {
# Verifica si el script se ejecuta como administrador
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Show-Menu {
param([string]$Title = "MENÚ PRINCIPAL")
Write-Host "`n$Title" -ForegroundColor $ColorInfo
Write-Host "======================" -ForegroundColor $ColorInfo
Write-Host "1. Detectar versiones de Office instaladas"
Write-Host "2. Desinstalar Office completamente"
Write-Host "3. Limpiar licencias residuales"
Write-Host "4. Limpiar archivos residuales"
Write-Host "5. Ejecutar todas las limpiezas (COMPLETO)"
Write-Host "6. Descargar herramienta oficial de Microsoft"
Write-Host "7. Información del sistema"
Write-Host "8. Salir"
Write-Host ""
}
function Get-OfficeVersions {
# Detecta versiones de Office instaladas
Write-Host "`nBuscando versiones de Office instaladas..." -ForegroundColor $ColorInfo
$officeVersions = @()
# Buscar en programas instalados
$installedPrograms = Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" -ErrorAction SilentlyContinue |
Where-Object { $_.DisplayName -like "*Office*" -or $_.DisplayName -like "*Microsoft 365*" }
if ($installedPrograms) {
Write-Host "`nVERSIONES ENCONTRADAS:" -ForegroundColor $ColorWarning
foreach ($program in $installedPrograms) {
Write-Host " - $($program.DisplayName)" -ForegroundColor $ColorInfo
Write-Host " Versión: $($program.DisplayVersion)" -ForegroundColor Gray
Write-Host " Desinstalador: $($program.UninstallString)" -ForegroundColor Gray
$officeVersions += $program
}
} else {
Write-Host "No se encontraron versiones de Office en el registro." -ForegroundColor $ColorWarning
}
# Buscar carpetas de Office
Write-Host "`nBuscando carpetas de Office..." -ForegroundColor $ColorInfo
$officePaths = @(
"C:\Program Files\Microsoft Office",
"C:\Program Files (x86)\Microsoft Office",
"C:\ProgramData\Microsoft\Office"
)
foreach ($path in $officePaths) {
if (Test-Path $path) {
Write-Host " - Carpeta encontrada: $path" -ForegroundColor $ColorSuccess
}
}
return $officeVersions
}
function Uninstall-OfficePrograms {
param([array]$Programs)
if (-not $Programs) {
Write-Host "No hay programas de Office para desinstalar." -ForegroundColor $ColorWarning
return
}
Write-Host "`nDESINSTALANDO PROGRAMAS DE OFFICE..." -ForegroundColor $ColorWarning
Write-Host "=====================================" -ForegroundColor $ColorWarning
foreach ($program in $Programs) {
Write-Host "`nDesinstalando: $($program.DisplayName)" -ForegroundColor $ColorInfo
if ($program.UninstallString) {
try {
# Extraer el comando de desinstalación
$uninstallCmd = $program.UninstallString
# Si contiene msiexec, agregar parámetros silenciosos
if ($uninstallCmd -like "*msiexec*") {
$uninstallCmd = $uninstallCmd.Replace("/I", "/X") + " /quiet /norestart"
}
Write-Host "Ejecutando: $uninstallCmd" -ForegroundColor Gray
# Ejecutar desinstalación
Start-Process "cmd.exe" -ArgumentList "/c $uninstallCmd" -Wait -NoNewWindow
Write-Host " ✓ Desinstalación completada" -ForegroundColor $ColorSuccess
} catch {
Write-Host " ✗ Error al desinstalar: $_" -ForegroundColor $ColorError
}
} else {
Write-Host " ⚠ No se encontró comando de desinstalación" -ForegroundColor $ColorWarning
}
}
}
function Remove-OfficeLicenses {
Write-Host "`nLIMPIANDO LICENCIAS DE OFFICE..." -ForegroundColor $ColorWarning
Write-Host "=================================" -ForegroundColor $ColorWarning
# Buscar archivo ospp.vbs en diferentes ubicaciones
$osppPaths = @(
"C:\Program Files\Microsoft Office\Office16",
"C:\Program Files\Microsoft Office\Office15",
"C:\Program Files\Microsoft Office\Office14",
"C:\Program Files (x86)\Microsoft Office\Office16",
"C:\Program Files (x86)\Microsoft Office\Office15",
"C:\Program Files (x86)\Microsoft Office\Office14"
)
$osppFound = $false
foreach ($path in $osppPaths) {
$osppFile = Join-Path $path "ospp.vbs"
if (Test-Path $osppFile) {
Write-Host "Encontrado ospp.vbs en: $path" -ForegroundColor $ColorSuccess
$osppFound = $true
try {
Set-Location $path
# Obtener información de licencias
Write-Host "`nLicencias instaladas:" -ForegroundColor $ColorInfo
$licenseInfo = cscript ospp.vbs /dstatus
# Extraer IDs de producto
$licenseIds = $licenseInfo | Select-String "Product key channel" | ForEach-Object {
$_.Line.Split(":")[1].Trim()
}
if ($licenseIds) {
foreach ($licenseId in $licenseIds) {
Write-Host "Eliminando licencia: $licenseId" -ForegroundColor $ColorInfo
cscript ospp.vbs /unpkey:$licenseId
}
} else {
Write-Host "No se encontraron licencias para eliminar." -ForegroundColor $ColorWarning
}
} catch {
Write-Host "Error al procesar licencias: $_" -ForegroundColor $ColorError
}
}
}
if (-not $osppFound) {
Write-Host "No se encontró el archivo ospp.vbs" -ForegroundColor $ColorWarning
}
}
function Remove-OfficeResidualFiles {
Write-Host "`nELIMINANDO ARCHIVOS RESIDUALES..." -ForegroundColor $ColorWarning
Write-Host "===================================" -ForegroundColor $ColorWarning
# Lista de carpetas a eliminar
$foldersToRemove = @(
"C:\Program Files\Microsoft Office",
"C:\Program Files (x86)\Microsoft Office",
"C:\ProgramData\Microsoft\Office",
"C:\ProgramData\Microsoft\OfficeSoftwareProtectionPlatform",
"$env:APPDATA\Microsoft\Office",
"$env:LOCALAPPDATA\Microsoft\Office"
)
# Lista de claves de registro a eliminar
$regKeysToRemove = @(
"HKLM:\SOFTWARE\Microsoft\Office",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office",
"HKCU:\Software\Microsoft\Office"
)
# Eliminar carpetas
foreach ($folder in $foldersToRemove) {
if (Test-Path $folder) {
try {
Write-Host "Eliminando carpeta: $folder" -ForegroundColor $ColorInfo
Remove-Item -Path $folder -Recurse -Force -ErrorAction Stop
Write-Host " ✓ Carpeta eliminada" -ForegroundColor $ColorSuccess
} catch {
Write-Host " ⚠ No se pudo eliminar completamente: $_" -ForegroundColor $ColorWarning
}
}
}
# Eliminar claves de registro (con precaución)
Write-Host "`n¿Desea eliminar las claves de registro de Office?" -ForegroundColor $ColorWarning
Write-Host "Esto es irreversible. (S/N)" -ForegroundColor $ColorWarning
$response = Read-Host
if ($response -eq "S" -or $response -eq "s") {
foreach ($regKey in $regKeysToRemove) {
if (Test-Path $regKey) {
try {
Write-Host "Eliminando clave de registro: $regKey" -ForegroundColor $ColorInfo
Remove-Item -Path $regKey -Recurse -Force -ErrorAction Stop
Write-Host " ✓ Clave eliminada" -ForegroundColor $ColorSuccess
} catch {
Write-Host " ⚠ No se pudo eliminar: $_" -ForegroundColor $ColorWarning
}
}
}
}
}
function Get-MicrosoftTool {
Write-Host "`nDESCARGANDO HERRAMIENTA OFICIAL DE MICROSOFT..." -ForegroundColor $ColorInfo
Write-Host "=================================================" -ForegroundColor $ColorInfo
$url = "https://aka.ms/SaRA-officeUninstallFromPC"
$downloadPath = "$env:USERPROFILE\Downloads\OfficeUninstallTool.exe"
Write-Host "URL: $url" -ForegroundColor Gray
Write-Host "Guardando en: $downloadPath" -ForegroundColor Gray
try {
# Descargar el archivo
Invoke-WebRequest -Uri $url -OutFile $downloadPath
Write-Host "`n✓ Herramienta descargada correctamente" -ForegroundColor $ColorSuccess
# Preguntar si ejecutar
Write-Host "`n¿Desea ejecutar la herramienta ahora? (S/N)" -ForegroundColor $ColorInfo
$response = Read-Host
if ($response -eq "S" -or $response -eq "s") {
Write-Host "Ejecutando herramienta..." -ForegroundColor $ColorInfo
Start-Process $downloadPath
}
} catch {
Write-Host "✗ Error al descargar: $_" -ForegroundColor $ColorError
Write-Host "Puede descargarla manualmente desde: $url" -ForegroundColor $ColorInfo
}
}
function Get-SystemInfo {
Write-Host "`nINFORMACIÓN DEL SISTEMA" -ForegroundColor $ColorInfo
Write-Host "======================" -ForegroundColor $ColorInfo
# Información básica del sistema
$os = Get-CimInstance Win32_OperatingSystem
$computer = Get-CimInstance Win32_ComputerSystem
Write-Host "Sistema Operativo: $($os.Caption)" -ForegroundColor Gray
Write-Host "Versión: $($os.Version)" -ForegroundColor Gray
Write-Host "Arquitectura: $($os.OSArchitecture)" -ForegroundColor Gray
Write-Host "Usuario: $env:USERNAME" -ForegroundColor Gray
Write-Host "Equipo: $($computer.Name)" -ForegroundColor Gray
# Espacio en disco
Write-Host "`nEspacio en disco:" -ForegroundColor $ColorInfo
Get-PSDrive C | Select-Object Used, Free | Format-Table -AutoSize
}
function Complete-Cleanup {
Write-Host "`nINICIANDO LIMPIEZA COMPLETA..." -ForegroundColor $ColorWarning
Write-Host "================================" -ForegroundColor $ColorWarning
# 1. Detectar versiones
$programs = Get-OfficeVersions
# 2. Desinstalar programas
if ($programs) {
Uninstall-OfficePrograms -Programs $programs
}
# 3. Limpiar licencias
Remove-OfficeLicenses
# 4. Limpiar archivos residuales
Remove-OfficeResidualFiles
Write-Host "`n=========================================" -ForegroundColor $ColorSuccess
Write-Host "LIMPIEZA COMPLETADA" -ForegroundColor $ColorSuccess
Write-Host "=========================================" -ForegroundColor $ColorSuccess
Write-Host "`nRecomendaciones:" -ForegroundColor $ColorInfo
Write-Host "1. Reinicie su computadora" -ForegroundColor Gray
Write-Host "2. Descargue Office 365 desde office.com" -ForegroundColor Gray
Write-Host "3. Instale con su cuenta Microsoft válida" -ForegroundColor Gray
}
# ============================================
# EJECUCIÓN PRINCIPAL
# ============================================
# Verificar permisos de administrador
if (-not (Test-Administrator)) {
Write-Host "`n⚠ ADVERTENCIA: Este script requiere permisos de administrador." -ForegroundColor $ColorError
Write-Host "Por favor, ejecute PowerShell como administrador y vuelva a intentarlo.`n" -ForegroundColor $ColorError
pause
exit 1
}
# Mostrar encabezado
Show-Header
# Bucle principal del menú
do {
Show-Menu
$choice = Read-Host "Seleccione una opción"
switch ($choice) {
"1" {
Show-Header
Get-OfficeVersions
pause
}
"2" {
Show-Header
$programs = Get-OfficeVersions
Uninstall-OfficePrograms -Programs $programs
pause
}
"3" {
Show-Header
Remove-OfficeLicenses
pause
}
"4" {
Show-Header
Remove-OfficeResidualFiles
pause
}
"5" {
Show-Header
Complete-Cleanup
pause
}
"6" {
Show-Header
Get-MicrosoftTool
pause
}
"7" {
Show-Header
Get-SystemInfo
pause
}
"8" {
Write-Host "`nSaliendo del programa..." -ForegroundColor $ColorInfo
exit 0
}
default {
Write-Host "Opción no válida. Intente nuevamente." -ForegroundColor $ColorError
pause
}
}
Show-Header
} while ($true)