# ============================================================================ # RMS TECH - INTERNET BOOST / Otimizacao de Internet (Ping / Rede / DNS) # Interface + logica · by @rms.tech · distribuicao gratuita / free to share # Executado pelo RMS-TECH-INTERNET-BOOST.bat (nao rode este .ps1 direto). # ============================================================================ $ErrorActionPreference = 'Stop' # --- pasta do script / script folder ------------------------------------ $ScriptDir = $PSScriptRoot if (-not $ScriptDir) { $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path } try { Set-Location -LiteralPath $ScriptDir } catch {} try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch {} # --- liga cores ANSI 24-bit no console classico / enable truecolor ----- if (-not $env:WT_SESSION) { try { Add-Type -Namespace RmsVT -Name Native -MemberDefinition '[DllImport("kernel32.dll")] public static extern IntPtr GetStdHandle(int h); [DllImport("kernel32.dll")] public static extern bool GetConsoleMode(IntPtr h, out uint m); [DllImport("kernel32.dll")] public static extern bool SetConsoleMode(IntPtr h, uint m);' $hOut = [RmsVT.Native]::GetStdHandle(-11) $cmode = [uint32]0 [void][RmsVT.Native]::GetConsoleMode($hOut, [ref]$cmode) [void][RmsVT.Native]::SetConsoleMode($hOut, $cmode -bor 0x0004) } catch {} } # --- tamanho da janela / window size (best effort) -------------------- try { $ui = $Host.UI.RawUI $mx = $ui.MaxPhysicalWindowSize $cols = [Math]::Min(104, [int]$mx.Width) $rws = [Math]::Min(46, [int]$mx.Height) $bs = $ui.BufferSize; if ($bs.Width -lt $cols) { $bs.Width = $cols }; $bs.Height = 3000; $ui.BufferSize = $bs $ws = $ui.WindowSize; $ws.Width = $cols; $ws.Height = $rws; $ui.WindowSize = $ws } catch {} # --- paleta / palette -------------------------------------------------- $ESC = [char]27 $RS = "$ESC[0m" $BLD = "$ESC[1m" function fg ($r, $g, $b) { "$ESC[38;2;$r;$g;${b}m" } function bgc ($r, $g, $b) { "$ESC[48;2;$r;$g;${b}m" } $CY = fg 90 210 255 $MG = fg 200 100 255 $GR = fg 90 230 150 $RD = fg 255 100 115 $YL = fg 255 205 100 $DM = fg 120 126 145 $WH = fg 236 239 246 $TX = fg 205 210 226 $DOT = [char]183 $PTR = [char]187 $AUP = [char]24 $ADN = [char]25 # --- banner (fonte ANSI Shadow, chars CP437-safe) ------------------- $RMS = @( '██████╗ ███╗ ███╗███████╗', '██╔══██╗████╗ ████║██╔════╝', '██████╔╝██╔████╔██║███████╗', '██╔══██╗██║╚██╔╝██║╚════██║', '██║ ██║██║ ╚═╝ ██║███████║', '╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝') $TECH = @( '████████╗███████╗ ██████╗██╗ ██╗', '╚══██╔══╝██╔════╝██╔════╝██║ ██║', ' ██║ █████╗ ██║ ███████║', ' ██║ ██╔══╝ ██║ ██╔══██║', ' ██║ ███████╗╚██████╗██║ ██║', ' ╚═╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝') function GradBlock ($arr, $c1, $c2, $ind) { $n = $arr.Count for ($i = 0; $i -lt $n; $i++) { if ($n -le 1) { $q = 0 } else { $q = $i / ($n - 1) } $cr = [int]($c1[0] + ($c2[0] - $c1[0]) * $q) $cg = [int]($c1[1] + ($c2[1] - $c1[1]) * $q) $cb = [int]($c1[2] + ($c2[2] - $c1[2]) * $q) Write-Host ((' ' * $ind) + (fg $cr $cg $cb) + $arr[$i] + $RS) } } function Header { try { Clear-Host } catch {} Write-Host '' GradBlock $RMS @(95, 215, 255) @(150, 130, 255) 6 GradBlock $TECH @(150, 130, 255) @(210, 95, 255) 6 Write-Host '' Write-Host (' ' + $DM + ('─' * 58) + $RS) Write-Host (' ' + $WH + $BLD + 'INTERNET BOOST' + $RS + $DM + " Ping / Rede / DNS $DOT Network Optimization" + $RS) Write-Host (' ' + $DM + 'by ' + $RS + $MG + $BLD + '@rms.tech' + $RS + $DM + " $DOT distribuicao gratuita" + $RS) Write-Host '' } # --- menu com setas / arrow-key menu ------------------------------- function Menu ($items, $title) { $sel = 0 $w = 58 while ($true) { Header if ($title) { Write-Host (' ' + $YL + $title + $RS); Write-Host '' } Write-Host (' ' + $DM + '┌' + ('─' * $w) + '┐' + $RS) Write-Host (' ' + $DM + '│' + (' ' * $w) + '│' + $RS) for ($i = 0; $i -lt $items.Count; $i++) { $lab = ' ' + $items[$i].Key + ' ' + $items[$i].Text if ($i -eq $sel) { $cell = ' ' + $PTR + ' ' + $lab $cell = $cell + (' ' * [Math]::Max(0, $w - $cell.Length)) Write-Host (' ' + $DM + '│' + $RS + (bgc 38 44 62) + (fg 130 232 255) + $BLD + $cell + $RS + $DM + '│' + $RS) } else { $cell = ' ' + $lab $cell = $cell + (' ' * [Math]::Max(0, $w - $cell.Length)) Write-Host (' ' + $DM + '│' + $RS + $TX + $cell + $RS + $DM + '│' + $RS) } } Write-Host (' ' + $DM + '│' + (' ' * $w) + '│' + $RS) Write-Host (' ' + $DM + '└' + ('─' * $w) + '┘' + $RS) Write-Host '' Write-Host (' ' + $DM + "$AUP $ADN" + $RS + $TX + ' navegar ' + $RS + $DM + 'Enter' + $RS + $TX + ' confirmar ' + $RS + $DM + 'Esc' + $RS + $TX + ' voltar' + $RS) $k = [Console]::ReadKey($true) if ($k.Key -eq 'UpArrow') { $sel = ($sel - 1 + $items.Count) % $items.Count; continue } if ($k.Key -eq 'DownArrow') { $sel = ($sel + 1) % $items.Count; continue } if ($k.Key -eq 'Enter') { return $items[$sel].Id } if ($k.Key -eq 'Escape') { return 'BACK' } foreach ($it in $items) { if ($it.Key -ne '' -and ([string]$k.KeyChar -eq [string]$it.Key)) { return $it.Id } } } } # --- helpers de status / status helpers --------------------------- function SLine ($txt) { Write-Host (' ' + $DM + ' ... ' + $RS + $TX + $txt + $RS) -NoNewline } function SOk ($txt) { Write-Host ("`r" + $ESC + '[2K' + ' ' + (bgc 30 90 55) + $GR + $BLD + ' OK ' + $RS + ' ' + $TX + $txt + $RS) } function SFail ($txt) { Write-Host ("`r" + $ESC + '[2K' + ' ' + (bgc 100 35 40) + $RD + $BLD + ' ERRO ' + $RS + ' ' + $TX + $txt + $RS) } function SWarn ($txt) { Write-Host ("`r" + $ESC + '[2K' + ' ' + (bgc 95 75 20) + $YL + $BLD + ' AVISO ' + $RS + ' ' + $TX + $txt + $RS) } function Bar ($total, $done) { $wd = 34 if ($total -le 0) { $f = 0 } else { $f = [int][Math]::Round($wd * $done / $total) } ' ' + $CY + ('█' * $f) + $DM + ('░' * ($wd - $f)) + $RS + $TX + (' {0}/{1}' -f $done, $total) + $RS } function GBox ($lines, $col) { $lines = @($lines) $w = 50 Write-Host (' ' + $col + $BLD + '╔' + ('═' * $w) + '╗' + $RS) foreach ($l in $lines) { $s = ' ' + $l if ($s.Length -gt $w) { $s = $s.Substring(0, $w) } $s = $s + (' ' * ($w - $s.Length)) Write-Host (' ' + $col + $BLD + '║' + $s + '║' + $RS) } Write-Host (' ' + $col + $BLD + '╚' + ('═' * $w) + '╝' + $RS) } function Pause2 { Write-Host '' Write-Host (' ' + $DM + 'pressione qualquer tecla para voltar ao menu...' + $RS) [void][Console]::ReadKey($true) } # --- executa reg.exe silencioso / run reg.exe quietly ------------ function RegRun { param([Parameter(ValueFromRemainingArguments = $true)] $a) $old = $ErrorActionPreference $ErrorActionPreference = 'SilentlyContinue' try { $null = & reg @a 2>&1 } catch {} $ok = ($LASTEXITCODE -eq 0) $ErrorActionPreference = $old return $ok } # --- chaves fixas / fixed keys ------------------------------------ $PSCHED_KEY = 'HKLM\SOFTWARE\Policies\Microsoft\Windows\Psched' $MSMQ_KEY = 'HKLM\SOFTWARE\Microsoft\MSMQ\Parameters' $IFACES_PS = 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces' $IFACES_REG = 'HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces' # --- descobre interfaces de rede configuradas / find configured NICs ---- function GetActiveInterfaceGuids { $out = @() Get-ChildItem -Path $IFACES_PS -ErrorAction SilentlyContinue | ForEach-Object { try { $p = Get-ItemProperty -LiteralPath $_.PSPath -ErrorAction SilentlyContinue if ($p -and ($p.DhcpIPAddress -or $p.IPAddress)) { $out += $_.PSChildName } } catch {} } return $out } function SafeName ($guid) { ($guid -replace '[{}]', '') } # --- lista de tweaks de registro / registry tweak list ------------- # GPEDIT "Limitar largura de banda reservavel" + REGEDIT (Interfaces + MSMQ) do roteiro function Tweaks { $items = @( @{ K = $PSCHED_KEY; N = 'NonBestEffortLimit'; T = 'REG_DWORD'; D = '0'; L = 'QoS: largura de banda reservavel liberada (0%)' } @{ K = $MSMQ_KEY; N = 'TCPNoDelay'; T = 'REG_DWORD'; D = '1'; L = 'MSMQ: TCPNoDelay = 1' } ) foreach ($g in (GetActiveInterfaceGuids)) { $k = "$IFACES_REG\$g" $items += @{ K = $k; N = 'TcpAckFrequency'; T = 'REG_DWORD'; D = '1'; L = ('Nagle off: TcpAckFrequency ' + $g) } $items += @{ K = $k; N = 'TCPNoDelay'; T = 'REG_DWORD'; D = '1'; L = ('Nagle off: TCPNoDelay ' + $g) } } return $items } # --- REDE: propriedades avancadas da placa / NIC advanced properties ---- $NicPropPatterns = @( @{ Pats = @('energy efficient ethernet', 'eficiencia de energia ethernet', 'eee') } @{ Pats = @('green ethernet', 'ethernet verde') } @{ Pats = @('power saving', 'economia de energia') } @{ Pats = @('interrupt moderation', 'moderacao de interrupcao') } ) function NormTxt ($s) { if (-not $s) { return '' } $t = $s.ToLowerInvariant() $map = @{ 'ç'='c'; 'ã'='a'; 'õ'='o'; 'á'='a'; 'â'='a'; 'é'='e'; 'ê'='e'; 'í'='i'; 'ó'='o'; 'ô'='o'; 'ú'='u' } foreach ($k in $map.Keys) { $t = $t.Replace($k, $map[$k]) } return $t } function GetTargetAdapters { try { Get-NetAdapter -Physical -ErrorAction SilentlyContinue | Where-Object { $_.Status -eq 'Up' } } catch { @() } } function GetTargetNicProps { $out = @() foreach ($ad in (GetTargetAdapters)) { $props = @() try { $props = Get-NetAdapterAdvancedProperty -Name $ad.Name -ErrorAction SilentlyContinue } catch {} foreach ($p in $props) { $norm = NormTxt $p.DisplayName foreach ($grp in $NicPropPatterns) { $hit = $false foreach ($pat in $grp.Pats) { if ($norm -like "*$pat*") { $hit = $true; break } } if ($hit) { $old = '' try { $old = [string]$p.RegistryValue[0] } catch {} $out += [pscustomobject]@{ Adapter = $ad.Name; DisplayName = $p.DisplayName; OldValue = $old } break } } } } return $out } function BackupNic ($bkdir) { (GetTargetNicProps) | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $bkdir 'NIC_Backup.json') -Encoding UTF8 $pm = @() foreach ($ad in (GetTargetAdapters)) { try { $cur = Get-NetAdapterPowerManagement -Name $ad.Name -ErrorAction SilentlyContinue $pm += [pscustomobject]@{ Adapter = $ad.Name; State = [string]$cur.AllowComputerToTurnOffDevice } } catch {} } $pm | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $bkdir 'NIC_PowerMgmt_Backup.json') -Encoding UTF8 } function ApplyNic { $done = 0; $skip = 0 foreach ($it in (GetTargetNicProps)) { SLine ('REDE: ' + $it.DisplayName + ' (' + $it.Adapter + ')') Start-Sleep -Milliseconds 50 try { Set-NetAdapterAdvancedProperty -Name $it.Adapter -DisplayName $it.DisplayName -RegistryValue '0' -ErrorAction Stop SOk ('REDE: ' + $it.DisplayName + ' = desativado (' + $it.Adapter + ')') $done++ } catch { SWarn ('REDE: ' + $it.DisplayName + ' nao suportado nesta placa, pulado') $skip++ } } foreach ($ad in (GetTargetAdapters)) { SLine ('Gerenciamento de energia: ' + $ad.Name) Start-Sleep -Milliseconds 50 try { Disable-NetAdapterPowerManagement -Name $ad.Name -ErrorAction Stop; SOk ('Economia de energia desativada: ' + $ad.Name) } catch { SWarn ('Gerenciamento de energia nao suportado em ' + $ad.Name) } } return @{ Done = $done; Skip = $skip } } function RestoreNic ($bkdir) { $f = Join-Path $bkdir 'NIC_Backup.json' if (Test-Path -LiteralPath $f) { try { $items = @(Get-Content -LiteralPath $f -Raw | ConvertFrom-Json) } catch { $items = @() } foreach ($it in $items) { if ($it -and $it.OldValue -ne '') { try { Set-NetAdapterAdvancedProperty -Name $it.Adapter -DisplayName $it.DisplayName -RegistryValue $it.OldValue -ErrorAction SilentlyContinue } catch {} } } } $f2 = Join-Path $bkdir 'NIC_PowerMgmt_Backup.json' if (Test-Path -LiteralPath $f2) { try { $pm = @(Get-Content -LiteralPath $f2 -Raw | ConvertFrom-Json) } catch { $pm = @() } foreach ($p in $pm) { try { if ($p.State -eq 'Enabled') { Enable-NetAdapterPowerManagement -Name $p.Adapter -ErrorAction SilentlyContinue } } catch {} } } } # --- DNS: adaptadores ativos / active adapters --------------------- function BackupDns ($bkdir) { $rows = @() foreach ($ad in (GetTargetAdapters)) { try { $cur = Get-DnsClientServerAddress -InterfaceIndex $ad.InterfaceIndex -AddressFamily IPv4 -ErrorAction SilentlyContinue $rows += [pscustomobject]@{ IfIndex = $ad.InterfaceIndex; IfAlias = $ad.Name; Servers = ($cur.ServerAddresses -join ',') } } catch {} } $rows | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $bkdir 'DNS_Backup.json') -Encoding UTF8 } function ApplyDns ($servers) { foreach ($ad in (GetTargetAdapters)) { try { Set-DnsClientServerAddress -InterfaceIndex $ad.InterfaceIndex -ServerAddresses $servers -ErrorAction SilentlyContinue } catch {} } try { Clear-DnsClientCache } catch {} } function RestoreDns ($bkdir) { $f = Join-Path $bkdir 'DNS_Backup.json' if (-not (Test-Path -LiteralPath $f)) { return } try { $rows = @(Get-Content -LiteralPath $f -Raw | ConvertFrom-Json) } catch { return } foreach ($r in $rows) { try { if ([string]::IsNullOrWhiteSpace($r.Servers)) { Set-DnsClientServerAddress -InterfaceIndex $r.IfIndex -ResetServerAddresses -ErrorAction SilentlyContinue } else { Set-DnsClientServerAddress -InterfaceIndex $r.IfIndex -ServerAddresses ($r.Servers -split ',') -ErrorAction SilentlyContinue } } catch {} } try { Clear-DnsClientCache } catch {} } # --- CMD: manutencao de rede (sem backup, comandos pontuais) --------- function RunMaintenance { SLine 'ipconfig /renew' Start-Sleep -Milliseconds 60 try { & ipconfig /renew *>$null } catch {} SOk 'ipconfig /renew' SLine 'ipconfig /flushdns' Start-Sleep -Milliseconds 60 try { & ipconfig /flushdns *>$null } catch {} SOk 'ipconfig /flushdns' SLine 'netsh winsock reset' Start-Sleep -Milliseconds 60 try { & netsh winsock reset *>$null } catch {} SOk 'netsh winsock reset (so vale depois de reiniciar)' } # --- tela de confirmacao / confirm screen -------------------- function Confirm ($tw, $nic, $dnsChoice) { Header $w = 58 Write-Host (' ' + $YL + 'Isto sera alterado no seu PC:' + $RS) Write-Host '' Write-Host (' ' + $TX + 'REGISTRO (QoS / Nagle / MSMQ):' + $RS) Write-Host (' ' + $DM + '┌' + ('─' * $w) + '┐' + $RS) foreach ($t in $tw) { $s = ' ' + $t.L if ($s.Length -gt $w) { $s = $s.Substring(0, $w) } $s = $s + (' ' * [Math]::Max(0, $w - $s.Length)) Write-Host (' ' + $DM + '│' + $RS + $TX + $s + $RS + $DM + '│' + $RS) } Write-Host (' ' + $DM + '└' + ('─' * $w) + '┘' + $RS) Write-Host '' Write-Host (' ' + $TX + 'PLACA DE REDE (EEE / Green Ethernet / Power Saving / Int. Moderation):' + $RS) if ($nic.Count -eq 0) { Write-Host (' ' + $DM + ' nenhuma dessas opcoes encontrada nas suas placas (normal)' + $RS) } else { foreach ($it in $nic) { Write-Host (' ' + $DM + ' ' + $DOT + ' ' + $it.DisplayName + ' (' + $it.Adapter + ') -> desligado' + $RS) } } Write-Host (' ' + $DM + ' ' + $DOT + ' gerenciamento de energia da placa -> desligado' + $RS) Write-Host '' $dnsLine = switch ($dnsChoice) { 'CF' { 'DNS: trocar para Cloudflare (1.1.1.1 / 1.0.0.1)' } 'GOOG' { 'DNS: trocar para Google (8.8.8.8 / 8.8.4.4)' } default { 'DNS: sem alteracao (mantem o atual)' } } Write-Host (' ' + $TX + $dnsLine + $RS) Write-Host '' Write-Host (' ' + $TX + 'MANUTENCAO (sempre roda, sem desfazer):' + $RS) Write-Host (' ' + $DM + ' ipconfig /renew ' + $DOT + ' ipconfig /flushdns ' + $DOT + ' netsh winsock reset' + $RS) Write-Host '' Write-Host (' ' + $DM + 'backup em ' + $RS + (fg 170 176 196) + (Join-Path $ScriptDir 'Backup_RMS_INTERNET') + $RS) Write-Host '' Write-Host (' ' + (bgc 30 90 55) + $BLD + ' S ' + $RS + $TX + ' aplicar agora ' + $RS + (bgc 100 35 40) + $BLD + ' N ' + $RS + $TX + ' cancelar' + $RS) while ($true) { $k = [Console]::ReadKey($true) $c = [string]$k.KeyChar if ($c -match '^[sySY]$') { return $true } if ($c -match '^[nN]$' -or $k.Key -eq 'Escape') { return $false } } } # --- aplicar / apply --------------------------------------- function RunApply ($dnsChoice) { Header Write-Host (' ' + $WH + $BLD + "1 $DOT BACKUP" + $RS) Write-Host '' $stamp = Get-Date -Format 'yyyy-MM-dd_HH-mm-ss' $bkdir = Join-Path (Join-Path $ScriptDir 'Backup_RMS_INTERNET') $stamp New-Item -ItemType Directory -Force -Path $bkdir | Out-Null $bkeys = @( @{ K = $PSCHED_KEY; F = 'Psched.reg' } @{ K = $MSMQ_KEY; F = 'MSMQ.reg' } ) foreach ($g in (GetActiveInterfaceGuids)) { $bkeys += @{ K = "$IFACES_REG\$g"; F = ('Interface_' + (SafeName $g) + '.reg') } } foreach ($x in $bkeys) { SLine $x.F Start-Sleep -Milliseconds 55 if (RegRun query $x.K) { if (RegRun export $x.K (Join-Path $bkdir $x.F) /y) { SOk ('backup ' + $x.F) } else { SWarn ('sem backup ' + $x.F) } } else { Set-Content -LiteralPath (Join-Path $bkdir ('MISSING_' + $x.F + '.txt')) -Value $x.K -Encoding ASCII SWarn ('nao existia, ok ' + $x.F) } } SLine 'NIC_Backup.json' Start-Sleep -Milliseconds 55 BackupNic $bkdir SOk 'backup propriedades de rede' SLine 'DNS_Backup.json' Start-Sleep -Milliseconds 55 BackupDns $bkdir SOk 'backup DNS' Write-Host '' Write-Host (' ' + $WH + $BLD + "2 $DOT REGISTRO / QoS / NAGLE / MSMQ" + $RS) Write-Host '' $tw = Tweaks $done = 0; $fail = 0 foreach ($t in $tw) { SLine $t.L Start-Sleep -Milliseconds 70 if (RegRun add $t.K /v $t.N /t $t.T /d $t.D /f) { SOk $t.L; $done++ } else { SFail $t.L; $fail++ } } Write-Host '' Write-Host (' ' + $WH + $BLD + "3 $DOT PLACA DE REDE" + $RS) Write-Host '' $nicRes = ApplyNic if ($dnsChoice -eq 'CF' -or $dnsChoice -eq 'GOOG') { Write-Host '' Write-Host (' ' + $WH + $BLD + "4 $DOT DNS" + $RS) Write-Host '' if ($dnsChoice -eq 'CF') { SLine 'DNS -> Cloudflare 1.1.1.1 / 1.0.0.1' Start-Sleep -Milliseconds 70 ApplyDns @('1.1.1.1', '1.0.0.1') SOk 'DNS -> Cloudflare 1.1.1.1 / 1.0.0.1' } else { SLine 'DNS -> Google 8.8.8.8 / 8.8.4.4' Start-Sleep -Milliseconds 70 ApplyDns @('8.8.8.8', '8.8.4.4') SOk 'DNS -> Google 8.8.8.8 / 8.8.4.4' } } Write-Host '' Write-Host (' ' + $WH + $BLD + "5 $DOT MANUTENCAO (CMD)" + $RS) Write-Host '' RunMaintenance Write-Host '' Write-Host (Bar $tw.Count $done) Write-Host '' if ($fail -eq 0) { GBox @( "TWEAKS APLICADOS $DOT REINICIE O PC", "TWEAKS APPLIED $DOT RESTART YOUR PC") $GR } else { GBox @("$fail item(s) de registro falharam.", 'Feche e rode como administrador.') $YL } if ($nicRes.Skip -gt 0) { Write-Host (' ' + $DM + ($nicRes.Skip.ToString() + ' propriedade(s) de rede nao existem nesta placa (normal).') + $RS) } Write-Host '' Write-Host (' ' + $DM + 'backup: ' + $RS + (fg 170 176 196) + $bkdir + $RS) Write-Host '' Write-Host (' ' + $MG + $BLD + 'curtiu? compartilha com a galera e segue @rms.tech' + $RS) try { Start-Process 'https://otimizar.superpackultimate.com/?de=packs' } catch {} Pause2 } # --- restaurar / restore -------------------------------- function RunRestore { Header Write-Host (' ' + $WH + $BLD + 'RESTAURAR / RESTORE' + $RS) Write-Host '' $bkroot = Join-Path $ScriptDir 'Backup_RMS_INTERNET' if (-not (Test-Path -LiteralPath $bkroot)) { GBox @('Nenhum backup encontrado.', 'No backup found.') $RD Pause2; return } $latest = Get-ChildItem -LiteralPath $bkroot -Directory -ErrorAction SilentlyContinue | Sort-Object Name -Descending | Select-Object -First 1 if (-not $latest) { GBox @('Nenhum backup encontrado.', 'No backup found.') $RD Pause2; return } Write-Host (' ' + $DM + 'de / from: ' + $RS + (fg 170 176 196) + $latest.FullName + $RS) Write-Host '' Write-Host (' ' + $WH + $BLD + 'removendo valores de registro adicionados' + $RS) Write-Host '' foreach ($t in (Tweaks)) { SLine ('remover ' + $t.N) Start-Sleep -Milliseconds 40 [void](RegRun delete $t.K /v $t.N /f) SOk ('removido ' + $t.N) } Write-Host '' Write-Host (' ' + $WH + $BLD + 'reimportando originais / re-importing originals' + $RS) Write-Host '' $imported = 0 Get-ChildItem -LiteralPath $latest.FullName -Filter *.reg -ErrorAction SilentlyContinue | ForEach-Object { SLine ('import ' + $_.Name) Start-Sleep -Milliseconds 40 if (RegRun import $_.FullName) { SOk ('import ' + $_.Name); $imported++ } else { SFail ('import ' + $_.Name) } } if ($imported -eq 0) { Write-Host (' ' + $DM + ' (nenhum .reg neste backup)' + $RS) } foreach ($mk in (Get-ChildItem -LiteralPath $latest.FullName -Filter 'MISSING_*.txt' -ErrorAction SilentlyContinue)) { $origKey = (Get-Content -LiteralPath $mk.FullName -Raw).Trim() [void](RegRun delete $origKey /f) SWarn ('chave removida (nao existia antes) ' + $mk.Name) } Write-Host '' Write-Host (' ' + $WH + $BLD + 'restaurando placa de rede / restoring NIC settings' + $RS) Write-Host '' SLine 'propriedades de rede originais' Start-Sleep -Milliseconds 70 RestoreNic $latest.FullName SOk 'placa de rede restaurada' Write-Host '' Write-Host (' ' + $WH + $BLD + 'restaurando DNS / restoring DNS' + $RS) Write-Host '' SLine 'DNS original' Start-Sleep -Milliseconds 70 RestoreDns $latest.FullName SOk 'DNS restaurado (ou voltou pro DHCP)' Write-Host '' GBox @("RESTAURADO $DOT REINICIE O PC", "RESTORED $DOT RESTART YOUR PC") $GR Pause2 } # ============================ MAIN ===================================== try { [Console]::CursorVisible = $false } catch {} try { while ($true) { $c = Menu @( @{ Id = 'APPLY'; Key = '1'; Text = "Aplicar otimizacoes $DOT Apply tweaks" } @{ Id = 'RESTORE'; Key = '2'; Text = "Restaurar ultimo backup $DOT Restore backup" } @{ Id = 'EXIT'; Key = '3'; Text = "Sair $DOT Exit" } ) '' if ($c -eq 'APPLY') { $s = Menu @( @{ Id = 'CF'; Key = 'A'; Text = 'DNS Cloudflare 1.1.1.1 / 1.0.0.1 · recomendado' } @{ Id = 'GOOG'; Key = 'B'; Text = 'DNS Google 8.8.8.8 / 8.8.4.4' } @{ Id = 'SKIP'; Key = 'C'; Text = 'Nao mexer no DNS (manter o atual)' } ) 'DNS a usar junto com os tweaks de rede:' if ($s -eq 'CF' -or $s -eq 'GOOG' -or $s -eq 'SKIP') { $tw = Tweaks $nic = GetTargetNicProps if (Confirm $tw $nic $s) { RunApply $s } } } elseif ($c -eq 'RESTORE') { RunRestore } elseif ($c -eq 'EXIT' -or $c -eq 'BACK') { break } } } catch { Write-Host '' Write-Host (' ' + $RD + $BLD + 'ERRO INESPERADO / UNEXPECTED ERROR:' + $RS) Write-Host (' ' + $TX + $_.Exception.Message + $RS) Write-Host '' Write-Host (' ' + $DM + 'pressione qualquer tecla para fechar...' + $RS) try { [void][Console]::ReadKey($true) } catch { Read-Host | Out-Null } } finally { try { [Console]::CursorVisible = $true } catch {} Write-Host $RS Write-Host '' }