Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal EnableExtensions
- title Parar Backup FTP Automatico
- :: Solicita permissao de administrador
- net session >nul 2>&1
- if not "%errorlevel%"=="0" (
- echo Solicitando permissao de administrador...
- powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
- exit /b
- )
- set "LOG=%USERPROFILE%\Desktop\Parar-Backup-FTP.log"
- echo ============================================================ > "%LOG%"
- echo PARAR BACKUP FTP AUTOMATICO >> "%LOG%"
- echo Data: %date% %time% >> "%LOG%"
- echo ============================================================ >> "%LOG%"
- echo.
- echo Procurando tarefas, servicos, processos e inicializacoes
- echo relacionados a "Backup FTP"...
- echo.
- powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
- "$ErrorActionPreference = 'SilentlyContinue';" ^
- "$pattern = 'backup[\s_-]*ftp';" ^
- "$log = $env:USERPROFILE + '\Desktop\Parar-Backup-FTP.log';" ^
- "function Log([string]$Text) { $Text | Tee-Object -FilePath $log -Append };" ^
- "Log '';" ^
- "Log '=== TAREFAS AGENDADAS ===';" ^
- "$tasks = Get-ScheduledTask | Where-Object {" ^
- " $actions = ($_.Actions | ForEach-Object { ($_.Execute + ' ' + $_.Arguments + ' ' + $_.WorkingDirectory) }) -join ' ';" ^
- " ($_.TaskName + ' ' + $_.TaskPath + ' ' + $actions) -match $pattern" ^
- "};" ^
- "if ($tasks) {" ^
- " foreach ($task in $tasks) {" ^
- " try { Stop-ScheduledTask -TaskName $task.TaskName -TaskPath $task.TaskPath -ErrorAction SilentlyContinue } catch {};" ^
- " try {" ^
- " Disable-ScheduledTask -TaskName $task.TaskName -TaskPath $task.TaskPath -ErrorAction Stop | Out-Null;" ^
- " Log ('DESATIVADA: ' + $task.TaskPath + $task.TaskName)" ^
- " } catch { Log ('ERRO AO DESATIVAR: ' + $task.TaskPath + $task.TaskName) }" ^
- " }" ^
- "} else { Log 'Nenhuma tarefa correspondente encontrada.' };" ^
- "Log '';" ^
- "Log '=== SERVICOS DO WINDOWS ===';" ^
- "$services = Get-CimInstance Win32_Service | Where-Object { ($_.Name + ' ' + $_.DisplayName + ' ' + $_.PathName) -match $pattern };" ^
- "if ($services) {" ^
- " foreach ($service in $services) {" ^
- " try { Stop-Service -Name $service.Name -Force -ErrorAction SilentlyContinue } catch {};" ^
- " try {" ^
- " Set-Service -Name $service.Name -StartupType Disabled -ErrorAction Stop;" ^
- " Log ('DESATIVADO: ' + $service.Name + ' - ' + $service.DisplayName)" ^
- " } catch { Log ('ERRO AO DESATIVAR: ' + $service.Name) }" ^
- " }" ^
- "} else { Log 'Nenhum servico correspondente encontrado.' };" ^
- "Log '';" ^
- "Log '=== PROCESSOS EM EXECUCAO ===';" ^
- "$processes = Get-CimInstance Win32_Process | Where-Object {" ^
- " $_.ProcessId -ne $PID -and (($_.Name + ' ' + $_.ExecutablePath + ' ' + $_.CommandLine) -match $pattern)" ^
- "};" ^
- "if ($processes) {" ^
- " foreach ($process in $processes) {" ^
- " try {" ^
- " Stop-Process -Id $process.ProcessId -Force -ErrorAction Stop;" ^
- " Log ('ENCERRADO: ' + $process.Name + ' PID=' + $process.ProcessId)" ^
- " } catch { Log ('ERRO AO ENCERRAR: ' + $process.Name + ' PID=' + $process.ProcessId) }" ^
- " }" ^
- "} else { Log 'Nenhum processo correspondente encontrado.' };" ^
- "Log '';" ^
- "Log '=== PASTAS DE INICIALIZACAO ===';" ^
- "$startupFolders = @(" ^
- " [Environment]::GetFolderPath('Startup')," ^
- " [Environment]::GetFolderPath('CommonStartup')" ^
- ") | Where-Object { $_ -and (Test-Path $_) };" ^
- "$startupFound = $false;" ^
- "$shell = New-Object -ComObject WScript.Shell;" ^
- "foreach ($folder in $startupFolders) {" ^
- " Get-ChildItem -LiteralPath $folder -File -Force | ForEach-Object {" ^
- " $file = $_;" ^
- " $text = $file.Name + ' ' + $file.FullName;" ^
- " if ($file.Extension -ieq '.lnk') {" ^
- " try {" ^
- " $shortcut = $shell.CreateShortcut($file.FullName);" ^
- " $text += ' ' + $shortcut.TargetPath + ' ' + $shortcut.Arguments + ' ' + $shortcut.WorkingDirectory" ^
- " } catch {}" ^
- " } elseif ($file.Extension -match '\.(bat|cmd|ps1|vbs|js|url|txt)$') {" ^
- " try { $text += ' ' + (Get-Content -LiteralPath $file.FullName -Raw -ErrorAction SilentlyContinue) } catch {}" ^
- " }" ^
- " if ($text -match $pattern) {" ^
- " $startupFound = $true;" ^
- " $newName = $file.FullName + '.disabled';" ^
- " if (Test-Path $newName) { $newName = $file.FullName + '.' + (Get-Date -Format 'yyyyMMddHHmmss') + '.disabled' };" ^
- " try {" ^
- " Rename-Item -LiteralPath $file.FullName -NewName ([IO.Path]::GetFileName($newName)) -ErrorAction Stop;" ^
- " Log ('DESATIVADO NA INICIALIZACAO: ' + $file.FullName)" ^
- " } catch { Log ('ERRO AO DESATIVAR INICIALIZACAO: ' + $file.FullName) }" ^
- " }" ^
- " }" ^
- "};" ^
- "if (-not $startupFound) { Log 'Nenhum arquivo correspondente encontrado nas pastas de inicializacao.' };" ^
- "Log '';" ^
- "Log '=== REGISTRO: RUN / RUNONCE ===';" ^
- "$backupDir = $env:USERPROFILE + '\Desktop\BackupFTP-Registro';" ^
- "New-Item -ItemType Directory -Path $backupDir -Force | Out-Null;" ^
- "$regLocations = @(" ^
- " @{ Ps='HKCU:\Software\Microsoft\Windows\CurrentVersion\Run'; Native='HKCU\Software\Microsoft\Windows\CurrentVersion\Run'; File='HKCU-Run.reg' }," ^
- " @{ Ps='HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce'; Native='HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce'; File='HKCU-RunOnce.reg' }," ^
- " @{ Ps='HKLM:\Software\Microsoft\Windows\CurrentVersion\Run'; Native='HKLM\Software\Microsoft\Windows\CurrentVersion\Run'; File='HKLM-Run.reg' }," ^
- " @{ Ps='HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce'; Native='HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce'; File='HKLM-RunOnce.reg' }," ^
- " @{ Ps='HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Run'; Native='HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Run'; File='HKLM-WOW6432-Run.reg' }" ^
- ");" ^
- "$regFound = $false;" ^
- "foreach ($location in $regLocations) {" ^
- " if (Test-Path $location.Ps) {" ^
- " $props = Get-ItemProperty -Path $location.Ps;" ^
- " $names = $props.PSObject.Properties | Where-Object { $_.Name -notmatch '^PS' };" ^
- " $matches = $names | Where-Object { ($_.Name + ' ' + [string]$_.Value) -match $pattern };" ^
- " if ($matches) {" ^
- " $regFound = $true;" ^
- " & reg.exe export $location.Native ($backupDir + '\' + $location.File) /y | Out-Null;" ^
- " foreach ($match in $matches) {" ^
- " try {" ^
- " Remove-ItemProperty -Path $location.Ps -Name $match.Name -ErrorAction Stop;" ^
- " Log ('REMOVIDO DA INICIALIZACAO DO REGISTRO: ' + $location.Native + ' -> ' + $match.Name + ' = ' + [string]$match.Value)" ^
- " } catch { Log ('ERRO AO REMOVER DO REGISTRO: ' + $location.Native + ' -> ' + $match.Name) }" ^
- " }" ^
- " }" ^
- " }" ^
- "};" ^
- "if (-not $regFound) { Log 'Nenhuma entrada correspondente encontrada no Registro.' };" ^
- "Log '';" ^
- "Log '=== RESULTADO ===';" ^
- "Log 'Verificacao concluida. Os itens encontrados foram interrompidos e desativados.';" ^
- "Log 'Nenhum arquivo da pasta de backup foi excluido.';" ^
- "Log ('Log salvo em: ' + $log);" ^
- "Write-Host '';" ^
- "Write-Host 'Concluido.' -ForegroundColor Green;" ^
- "Write-Host ('Relatorio salvo em: ' + $log);" ^
- "Write-Host 'Nenhum arquivo de backup foi apagado.';"
- echo.
- echo A janela sera fechada automaticamente em 10 segundos.
- timeout /t 10 /nobreak >nul
- exit /b
Advertisement
Add Comment
Please, Sign In to add comment