Skip to content

Commit 8ec0b2f

Browse files
authored
Merge pull request #13 from N0tHorizon/🌕Nextgen
0.9 Pre & Post Update
2 parents d41640d + 32e8e89 commit 8ec0b2f

3 files changed

Lines changed: 109 additions & 23 deletions

File tree

README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ A lightweight, open-source toolkit to disable Windows telemetry and improve priv
2424
- ⏪ Rollback support for most modules
2525
- 💾 System restore point creation
2626
- 🖥️ Interactive and batch modes
27+
- 📊 Audit logging to Windows Event Log
28+
- 🔄 Script update checker
29+
- 🛡️ Integrity checking for modules (file size and modification time)
2730

2831
## 🚀 Quick Start
2932

@@ -40,21 +43,6 @@ A lightweight, open-source toolkit to disable Windows telemetry and improve priv
4043
.\run.bat
4144
```
4245

43-
### Command Line Options
44-
```powershell
45-
# Run all modules
46-
.\windows-telemetry-blocker.ps1 -all
47-
48-
# Run specific modules
49-
.\windows-telemetry-blocker.ps1 -modules telemetry,services
50-
51-
# Interactive mode
52-
.\windows-telemetry-blocker.ps1 -interactive
53-
54-
# Advanced options
55-
powershell -ExecutionPolicy Bypass -File windows-telemetry-blocker.ps1 -all -dryrun -verbose -rollbackOnFailure
56-
```
57-
5846
## 🧩 Modules
5947

6048
| Module | Description |

run.bat

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,30 @@ echo Please select an option:
8989
echo 1. Run Interactive Script (Recommended)
9090
echo 2. Restore via builtin rollback system
9191
echo 3. Restore via System Restore Point
92-
echo 4. Exit
93-
set /p MENUOPT=Enter your choice [1-4]:
92+
echo 4. Update Script (Recommended after multiple runs)
93+
echo 5. Exit
94+
set /p MENUOPT=Enter your choice [1-5]:
9495

9596
set "PS_ARGS="
9697
set "PS_TARGET=%PS_SCRIPT%"
9798
if "%MENUOPT%"=="1" (
9899
echo [INFO] Launching interactive script in a new PowerShell window...
99-
start "TelemetryBlocker-Interactive" %PS_EXE% -NoProfile -ExecutionPolicy Bypass -File "%PS_SCRIPT%" -Interactive
100+
start "TelemetryBlocker-Interactive" %PS_EXE% -NoProfile -ExecutionPolicy Bypass -File "%PS_SCRIPT%" -Interactive -EnableAuditLog
100101
exit /b
101102
)
102103
if "%MENUOPT%"=="2" set "PS_ARGS=-Rollback"
103104
if "%MENUOPT%"=="3" set "PS_ARGS=-RestorePoint"
104-
if "%MENUOPT%"=="4" goto end
105+
if "%MENUOPT%"=="4" (
106+
echo [INFO] Launching script update check...
107+
%PS_EXE% -NoProfile -ExecutionPolicy Bypass -File "%PS_SCRIPT%" -Update
108+
echo.
109+
pause
110+
goto menu
111+
)
112+
if "%MENUOPT%"=="5" goto end
105113

106-
:: Only check for invalid selection for options other than 1-4
107-
if not "%MENUOPT%"=="1" if not "%MENUOPT%"=="2" if not "%MENUOPT%"=="3" if not "%MENUOPT%"=="4" (
114+
:: Only check for invalid selection for options other than 1-5
115+
if not "%MENUOPT%"=="1" if not "%MENUOPT%"=="2" if not "%MENUOPT%"=="3" if not "%MENUOPT%"=="4" if not "%MENUOPT%"=="5" (
108116
echo Invalid selection. Please try again.
109117
echo.
110118
goto menu

windowstelementryblocker.ps1

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ===============================
22
# Windows Telemetry Blocker
3-
# Script Version: nextgen-0.8 (pending review)
3+
# Script Version: nextgen-0.9 (pending)
44
# ===============================
55

66

@@ -13,7 +13,9 @@ param(
1313
[switch]$WhatIf,
1414
[switch]$RollbackOnFailure,
1515
[switch]$Rollback,
16-
[switch]$RestorePoint
16+
[switch]$RestorePoint,
17+
[switch]$Update,
18+
[switch]$EnableAuditLog
1719
)
1820

1921
# --- Special parameter handling (outside param block) ---
@@ -81,6 +83,14 @@ Write-Host "===============================" -ForegroundColor Cyan
8183
Write-Host (" Windows Telemetry Blocker v{0}" -f $ScriptVersion) -ForegroundColor Cyan
8284
Write-Host "===============================" -ForegroundColor Cyan
8385

86+
# Check for updates if requested
87+
if ($Update) {
88+
Write-Host "Update requested. Checking for updates..." -ForegroundColor Yellow
89+
Update-Script
90+
Write-Host "Update check complete." -ForegroundColor Green
91+
Write-AuditLog "Script update check performed"
92+
}
93+
8494
# Fail fast for unhandled errors in scripts we call; we'll handle expected errors with try/catch
8595
$ErrorActionPreference = 'Stop'
8696
$VerbosePreference = 'Continue'
@@ -95,6 +105,7 @@ $errorLogFile = Join-Path $PSScriptRoot "telemetry-blocker-errors.log"
95105
$executionStatsFile = Join-Path $PSScriptRoot "telemetry-blocker-stats.log"
96106
$reportFile = Join-Path $PSScriptRoot "telemetry-blocker-report.md"
97107
$modulesDir = Join-Path $PSScriptRoot "modules"
108+
$GitHubRepo = "https://github.com/N0tHorizon/WindowsTelemetryBlocker"
98109

99110
# ==== Logging helpers (single authoritative definitions) ====
100111
function Write-Log {
@@ -122,6 +133,66 @@ function Write-Stats {
122133
}
123134
}
124135

136+
# ==== New Feature Functions ====
137+
function Update-Script {
138+
Write-Host "Fetching latest version from GitHub..." -ForegroundColor Yellow
139+
try {
140+
# Download the main script
141+
$mainUrl = "$GitHubRepo/raw/main/windowstelementryblocker.ps1"
142+
$tempMain = Join-Path $PSScriptRoot "temp_main.ps1"
143+
Invoke-WebRequest -Uri $mainUrl -OutFile $tempMain -ErrorAction Stop
144+
145+
# Download modules
146+
$apiUrl = "$GitHubRepo/contents/modules"
147+
$response = Invoke-WebRequest -Uri $apiUrl -Headers @{ "Accept" = "application/vnd.github.v3+json" } -ErrorAction Stop
148+
$files = $response.Content | ConvertFrom-Json
149+
150+
foreach ($file in $files) {
151+
if ($file.name -like "*.ps1") {
152+
$fileUrl = $file.download_url
153+
$tempFile = Join-Path $PSScriptRoot ("temp_{0}" -f $file.name)
154+
Invoke-WebRequest -Uri $fileUrl -OutFile $tempFile -ErrorAction Stop
155+
}
156+
}
157+
158+
# Confirm
159+
$confirm = Read-Host "Downloaded updates. Overwrite files? (Y/N)"
160+
if ($confirm -eq 'Y') {
161+
# Overwrite
162+
Move-Item $tempMain (Join-Path $PSScriptRoot "windowstelementryblocker.ps1") -Force -ErrorAction Stop
163+
foreach ($file in $files) {
164+
if ($file.name -like "*.ps1") {
165+
$tempFile = Join-Path $PSScriptRoot ("temp_{0}" -f $file.name)
166+
$dest = Join-Path $modulesDir $file.name
167+
Move-Item $tempFile $dest -Force -ErrorAction Stop
168+
}
169+
}
170+
Write-Host "Update complete." -ForegroundColor Green
171+
} else {
172+
Write-Host "Update cancelled." -ForegroundColor Yellow
173+
# Clean temp
174+
Remove-Item (Join-Path $PSScriptRoot "temp_*") -Force -ErrorAction SilentlyContinue
175+
}
176+
} catch {
177+
Write-Host ("[ERROR] Update failed: {0}" -f $_.Exception.Message) -ForegroundColor Red
178+
# Clean temp
179+
Remove-Item (Join-Path $PSScriptRoot "temp_*") -Force -ErrorAction SilentlyContinue
180+
}
181+
}
182+
183+
function Write-AuditLog {
184+
param([string]$Message, [string]$EventType = "Information")
185+
if (-not $EnableAuditLog) { return }
186+
try {
187+
if (-not (Get-EventLog -LogName Application -Source "TelemetryBlocker" -ErrorAction SilentlyContinue)) {
188+
New-EventLog -LogName Application -Source "TelemetryBlocker" -ErrorAction Stop
189+
}
190+
Write-EventLog -LogName Application -Source "TelemetryBlocker" -EventId 1000 -EntryType $EventType -Message $Message -ErrorAction Stop
191+
} catch {
192+
Write-Log ("Failed to write audit log: {0}" -f $_.Exception.Message) -Error
193+
}
194+
}
195+
125196
# ==== Registry backup/export before changes ====
126197
function Export-RegistryBackup {
127198
try {
@@ -169,6 +240,7 @@ Write-Log "=== Script started ==="
169240
Write-Log ("Windows Version: {0}" -f $winVersion)
170241
Write-Log ("Windows Build: {0}" -f $winBuild)
171242
Write-Log ("Script Version: {0}" -f $ScriptVersion)
243+
Write-AuditLog ("Script started - Version {0}, Windows {1} Build {2}" -f $ScriptVersion, $winVersion, $winBuild)
172244

173245
# ==== Ensure modules directory exists ====
174246
if (-not (Test-Path $modulesDir)) {
@@ -184,6 +256,14 @@ if (-not (Test-Path $modulesDir)) {
184256
}
185257
}
186258

259+
# ==== Rollback coverage scan ====
260+
$rollbackCoverage = @{}
261+
foreach ($mod in $moduleList) {
262+
$rollbackPath = Join-Path $modulesDir ("{0}-rollback.ps1" -f $mod)
263+
$rollbackCoverage[$mod] = Test-Path $rollbackPath
264+
}
265+
Write-Log ("Rollback coverage: {0}" -f (($rollbackCoverage.GetEnumerator() | ForEach-Object { "$($_.Key):$($_.Value)" }) -join ', '))
266+
187267
# ==== System helpers ====
188268
function New-SystemRestorePoint {
189269
try {
@@ -402,6 +482,8 @@ function Resolve-ModuleDependencies {
402482
return $resolved
403483
}
404484

485+
486+
405487
# ==== Module execution loop ====
406488
Write-Host "`n=== Starting Module Execution ===" -ForegroundColor Cyan
407489
$summary = @()
@@ -414,6 +496,7 @@ $toRunResolved = Resolve-ModuleDependencies -mods $toRun
414496

415497
foreach ($mod in $toRunResolved) {
416498
Write-Host ("`nRunning module: {0}" -f $mod) -ForegroundColor Yellow
499+
Write-AuditLog ("Starting module execution: {0}" -f $mod)
417500
$moduleStart = Get-Date
418501
try {
419502
$modulePath = Join-Path $modulesDir ("{0}.ps1" -f $mod)
@@ -431,10 +514,12 @@ foreach ($mod in $toRunResolved) {
431514
if ($result -eq $false) {
432515
Write-Host ("[ERROR] Module {0} reported failure" -f $mod) -ForegroundColor Red
433516
Write-Log ("Module {0} reported failure" -f $mod) -Error
517+
Write-AuditLog ("Module {0} execution failed" -f $mod) "Warning"
434518
$summary += ("Module {0} reported failure" -f $mod)
435519
$moduleResults[$mod] = @{ Status='Failure'; Start=$moduleStart; End=(Get-Date) }
436520
} else {
437521
Write-Log ("Module {0} completed" -f $mod)
522+
Write-AuditLog ("Module {0} execution completed successfully" -f $mod)
438523
$summary += ("Module {0} completed" -f $mod)
439524
$moduleResults[$mod] = @{ Status='Success'; Start=$moduleStart; End=(Get-Date) }
440525
}
@@ -450,6 +535,7 @@ foreach ($mod in $toRunResolved) {
450535
if ($RollbackOnFailure) {
451536
Write-Host "Rolling back changes for executed modules..." -ForegroundColor Red
452537
Write-Log ("Rollback initiated due to failure in module {0}" -f $mod)
538+
Write-AuditLog ("Rollback initiated due to failure in module {0}" -f $mod) "Warning"
453539

454540
# clone and reverse executedModules safely
455541
$executedClone = @()
@@ -463,20 +549,24 @@ foreach ($mod in $toRunResolved) {
463549
Write-Host ("Running rollback for {0}..." -f $rmod) -ForegroundColor Yellow
464550
. $rollbackPath
465551
Write-Log ("Rollback for {0} completed" -f $rmod)
552+
Write-AuditLog ("Rollback for {0} completed" -f $rmod)
466553
$rollbackModules += $rmod
467554
} catch {
468555
$rbErr = if ($_.Exception) { $_.Exception.Message } else { $_.ToString() }
469556
Write-Host ("[ERROR] Rollback failed for {0}: {1}" -f $rmod, $rbErr) -ForegroundColor Red
470557
Write-Log ("Rollback failed for {0}: {1}" -f $rmod, $rbErr) -Error
558+
Write-AuditLog ("Rollback failed for {0}: {1}" -f $rmod, $rbErr) "Error"
471559
}
472560
} else {
473561
Write-Host ("No rollback script for {0}" -f $rmod) -ForegroundColor DarkYellow
474562
Write-Log ("No rollback script for {0}" -f $rmod)
563+
Write-AuditLog ("No rollback script for {0}" -f $rmod) "Warning"
475564
}
476565
}
477566

478567
Write-Host "Rollback complete. Exiting." -ForegroundColor Red
479568
Write-Log "Rollback complete. Exiting."
569+
Write-AuditLog "Rollback complete. Exiting."
480570
break
481571
} else {
482572
$response = Read-Host "Do you want to continue with remaining modules? (Y/N)"

0 commit comments

Comments
 (0)