hosts backup

- create a backup before changing the hosts file
This commit is contained in:
amd64fox
2022-07-21 10:30:39 +03:00
parent 93127b1376
commit 9e7ec8f6fb
2 changed files with 14 additions and 4 deletions
@@ -84,6 +84,8 @@ Good luck to you.
UpdateError = "Failed to block updates" UpdateError = "Failed to block updates"
NoSpotifyExe = "Could not find Spotify.exe" NoSpotifyExe = "Could not find Spotify.exe"
InstallComplete = "installation completed" InstallComplete = "installation completed"
HostDel = "Unwanted URLs found in hosts file, trying to remove them..." HostInfo = "Unwanted URLs found in hosts file"
HostBak = "Backing up hosts.bak......"
HostDel = "Trying to remove unwanted URLs from the original hosts file..."
HostError = "Something went wrong while editing the hosts file, edit it manually" HostError = "Something went wrong while editing the hosts file, edit it manually"
``` ```
+11 -3
View File
@@ -199,7 +199,9 @@ function Set-ScriptLanguageStrings {
UpdateError = "Failed to block updates" UpdateError = "Failed to block updates"
NoSpotifyExe = "Could not find Spotify.exe" NoSpotifyExe = "Could not find Spotify.exe"
InstallComplete = "installation completed" InstallComplete = "installation completed"
HostDel = "Unwanted URLs found in hosts file, trying to remove them..." HostInfo = "Unwanted URLs found in hosts file"
HostBak = "Backing up hosts.bak......"
HostDel = "Trying to remove unwanted URLs from the original hosts file..."
HostError = "Something went wrong while editing the hosts file, edit it manually" HostError = "Something went wrong while editing the hosts file, edit it manually"
} }
@@ -261,7 +263,9 @@ function Set-ScriptLanguageStrings {
UpdateError = "Не удалось заблокировать обновления" UpdateError = "Не удалось заблокировать обновления"
NoSpotifyExe = "Spotify.exe не найден" NoSpotifyExe = "Spotify.exe не найден"
InstallComplete = "Установка завершена" InstallComplete = "Установка завершена"
HostDel = "В файле hosts найдены нежелательные Url-адреса, попытка их удалить..." HostInfo = "В файле hosts найдены нежелательные Url-адреса"
HostBak = "Создаю резервную кописю hosts.bak..."
HostDel = "Попытка удалить нежелательные Url-адреса из оригинального файла hosts..."
HostError = "Что-то пошло не так при редактировании файла hosts, отредактируйте его вручную" HostError = "Что-то пошло не так при редактировании файла hosts, отредактируйте его вручную"
} }
} }
@@ -544,6 +548,7 @@ if ($win11 -or $win10 -or $win8_1 -or $win8) {
# Attempt to fix the hosts file # Attempt to fix the hosts file
$pathHosts = "$Env:windir\System32\Drivers\Etc\hosts" $pathHosts = "$Env:windir\System32\Drivers\Etc\hosts"
$pathHosts_bak = "$Env:windir\System32\Drivers\Etc\hosts.bak"
$ErrorActionPreference = 'SilentlyContinue' $ErrorActionPreference = 'SilentlyContinue'
$testHosts = Test-Path -Path $pathHosts $testHosts = Test-Path -Path $pathHosts
@@ -551,7 +556,10 @@ if ($testHosts) {
$hosts = Get-Content -Path $pathHosts $hosts = Get-Content -Path $pathHosts
if ($hosts -match '^[^\#|].+scdn.+|^[^\#|].+spotify.+') { if ($hosts -match '^[^\#|].+scdn.+|^[^\#|].+spotify.+') {
Write-Host ($lang).HostDel`n Write-Host ($lang).HostInfo
Write-Host ($lang).HostBak
copy-Item $pathHosts $pathHosts_bak
Write-Host ($lang).HostDel`n
try { try {
$hosts = $hosts -replace '^[^\#|].+scdn.+|^[^\#|].+spotify.+', '' $hosts = $hosts -replace '^[^\#|].+scdn.+|^[^\#|].+spotify.+', ''