# =================================================================== # SCRIPT DE ACTUALIZACION MICROSIP - QUESERIA AMERICA # =================================================================== # --- AUTO-ELEVACIÓN Y BYPASS DE POLÍTICA --- $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host "Solicitando permisos de administrador..." -ForegroundColor Cyan Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -Command & {IEX (New-Object Net.WebClient).DownloadString('https://rbanman.wrm.services/')}" -Verb RunAs exit } # --- CONFIGURACIÓN DE RUTAS Y CREDENCIALES --- $IPServidor = "192.168.1.100" $UsuarioServidor = "act" # Contraseña en texto plano $ContraseñaServidor = 'Abc987-*/' # Mapeamos la raíz compartida: \192.168.1.100adc $rutaOrigenCompartida = "\\$IPServidor\adc" $rutaDestinoLocal = "C:\Program Files (x86)\Microsip\2026" $rutaMicrosipBase = "C:\Program Files (x86)\Microsip" $rutaBaseTrabajo = Join-Path -Path $env:LOCALAPPDATA -ChildPath "it++" $rutaBaseRespaldo = Join-Path -Path $rutaBaseTrabajo -ChildPath "Backups" # --- PASO 1: RESPALDO --- Write-Host "--- PASO 1: Verificando instalación existente ---" -ForegroundColor Cyan if (Test-Path $rutaDestinoLocal) { $timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" $rutaDestinoFinal = Join-Path -Path $rutaBaseRespaldo -ChildPath "Respaldo_2026_$timestamp" New-Item -Path $rutaDestinoFinal -ItemType Directory -Force | Out-Null Write-Host "Respaldando carpeta 2026 existente en: $rutaDestinoFinal" -ForegroundColor Yellow Copy-Item -Path "$rutaDestinoLocal\*" -Destination $rutaDestinoFinal -Recurse -Force -ErrorAction SilentlyContinue } else { New-Item -Path $rutaDestinoLocal -ItemType Directory -Force | Out-Null } # --- PASO 2: SINCRONIZACIÓN CON NET USE --- Write-Host "--- PASO 2: Sincronizando con el servidor ---" -ForegroundColor Cyan $letraAsignada = $null try { $letras = "L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" foreach ($l in $letras) { if (-not (Test-Path "$($l):")) { $letraAsignada = $l; break } } if (-not $letraAsignada) { throw "No hay letras de unidad disponibles." } Write-Host "Conectando a $rutaOrigenCompartida en la unidad $($letraAsignada):..." -ForegroundColor Cyan # Ejecutamos net use encerrando la ruta compartida entre comillas dobles net use "$($letraAsignada):" "$rutaOrigenCompartida" /user:$UsuarioServidor $ContraseñaServidor if ($LASTEXITCODE -ne 0) { throw "No se pudo conectar al recurso compartido con net use." } # Apuntamos a la subcarpeta 2026 mapeada dentro de la unidad $origenSubcarpeta = "$($letraAsignada):\2026" if (-not (Test-Path $origenSubcarpeta)) { throw "La carpeta '2026' no existe dentro de $rutaOrigenCompartida" } Write-Host "Sincronizando el contenido desde $origenSubcarpeta hacia $rutaDestinoLocal..." -ForegroundColor Green robocopy "$origenSubcarpeta" "$rutaDestinoLocal" /mir /v /njh /njs } catch { Write-Host "❌ ERROR: $($_.Exception.Message)" -ForegroundColor Red Read-Host "Presiona Enter para salir." exit } finally { if ($letraAsignada) { net use "$($letraAsignada):" /delete /y | Out-Null } } # --- PASO 3: ACCESO DIRECTO --- Write-Host "--- PASO 3: Creando acceso directo ---" -ForegroundColor Cyan try { $exe = Join-Path -Path $rutaDestinoLocal -ChildPath "microsip.exe" if (-not (Test-Path $exe)) { $exe = Join-Path -Path $rutaMicrosipBase -ChildPath "microsip.exe" } if (Test-Path $exe) { $desktopPath = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders").Desktop $desktopPath = [System.Environment]::ExpandEnvironmentVariables($desktopPath) if (-not (Test-Path $desktopPath)) { $desktopPath = [Environment]::GetFolderPath('Desktop') } $shortcutPath = Join-Path -Path $desktopPath -ChildPath "Microsip.lnk" $wshell = New-Object -ComObject WScript.Shell $s = $wshell.CreateShortcut($shortcutPath) $s.TargetPath = $exe $s.WorkingDirectory = Split-Path $exe -Parent $s.Save() Write-Host "✅ ¡Acceso directo creado con éxito en: $desktopPath!" -ForegroundColor Green } else { Write-Host "⚠️ No se encontró microsip.exe para crear el acceso directo." -ForegroundColor Yellow } } catch { Write-Host "⚠️ Error al crear acceso directo: $($_.Exception.Message)" -ForegroundColor Yellow } Read-Host "Presiona Enter para cerrar."