#Requires -RunAsAdministrator <# .SYNOPSIS Blocks SolidWorks telemetry domains via hosts file while preserving licensing. .DESCRIPTION This script modifies the Windows hosts file to block telemetry/analytics domains from Dassault Systèmes/SolidWorks while keeping licensing servers accessible for license activation/deactivation. .NOTES Author: Atomaste Solution Requires: Administrator privileges Creates backup of hosts file before modification #> param( [switch]$Undo # Use -Undo to restore the original hosts file ) $hostsPath = "C:\Windows\System32\drivers\etc\hosts" $backupPath = "C:\Windows\System32\drivers\etc\hosts.backup.solidworks" $markerStart = "# === SOLIDWORKS TELEMETRY BLOCK START ===" $markerEnd = "# === SOLIDWORKS TELEMETRY BLOCK END ===" # Telemetry domains to block $blockDomains = @( "api.3ds.com", "www.3ds.com", "swym.3ds.com", "iam.3ds.com", "cas.3ds.com", "eu1-ds-iam.3dexperience.3ds.com", "eu1-ds.3dexperience.3ds.com", "update.solidworks.com", "www.solidworks.com", "sentry.io", "o136956.ingest.sentry.io", "telemetry.solidworks.com", "analytics.3ds.com", "collect.3ds.com", "ifwe.3ds.com", "eu1-ifwe.3dexperience.3ds.com", "passport.3ds.com", "3dswym.3ds.com" ) # Licensing domains - DO NOT BLOCK $licensingDomains = @( "activation.solidworks.com", "license.solidworks.com", "licensing.solidworks.com" ) function Test-IsAdmin { $currentUser = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object Security.Principal.WindowsPrincipal($currentUser) return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } function Backup-HostsFile { if (-not (Test-Path $backupPath)) { Copy-Item -Path $hostsPath -Destination $backupPath -Force Write-Host "[OK] Backup created: $backupPath" -ForegroundColor Green } else { Write-Host "[INFO] Backup already exists: $backupPath" -ForegroundColor Yellow } } function Remove-SolidWorksBlock { $content = Get-Content $hostsPath -Raw if ($content -match [regex]::Escape($markerStart)) { $pattern = "$([regex]::Escape($markerStart))[\s\S]*?$([regex]::Escape($markerEnd))\r?\n?" $newContent = $content -replace $pattern, "" Set-Content -Path $hostsPath -Value $newContent.TrimEnd() -Force -NoNewline Add-Content -Path $hostsPath -Value "" Write-Host "[OK] SolidWorks telemetry block removed from hosts file" -ForegroundColor Green return $true } return $false } function Add-SolidWorksBlock { $content = Get-Content $hostsPath -Raw # Check if block already exists if ($content -match [regex]::Escape($markerStart)) { Write-Host "[INFO] SolidWorks telemetry block already exists. Updating..." -ForegroundColor Yellow Remove-SolidWorksBlock | Out-Null $content = Get-Content $hostsPath -Raw } # Build the block $blockContent = @() $blockContent += "" $blockContent += $markerStart $blockContent += "# Blocks telemetry/analytics while preserving licensing" $blockContent += "# Generated: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" $blockContent += "#" $blockContent += "# PRESERVED (licensing - NOT blocked):" foreach ($domain in $licensingDomains) { $blockContent += "# - $domain" } $blockContent += "#" $blockContent += "# BLOCKED (telemetry/analytics):" foreach ($domain in $blockDomains) { $blockContent += "127.0.0.1 $domain" } $blockContent += $markerEnd Add-Content -Path $hostsPath -Value ($blockContent -join "`r`n") -Force Write-Host "[OK] SolidWorks telemetry domains blocked" -ForegroundColor Green } function Show-Status { Write-Host "`n=== HOSTS FILE STATUS ===" -ForegroundColor Cyan $content = Get-Content $hostsPath -Raw if ($content -match [regex]::Escape($markerStart)) { Write-Host "[ACTIVE] SolidWorks telemetry block is in place" -ForegroundColor Green } else { Write-Host "[INACTIVE] SolidWorks telemetry block not found" -ForegroundColor Yellow } Write-Host "`nBlocked domains:" -ForegroundColor White foreach ($domain in $blockDomains) { $blocked = $content -match "127\.0\.0\.1\s+$([regex]::Escape($domain))" if ($blocked) { Write-Host " [X] $domain" -ForegroundColor Red } else { Write-Host " [ ] $domain" -ForegroundColor Gray } } Write-Host "`nLicensing domains (should be accessible):" -ForegroundColor White foreach ($domain in $licensingDomains) { try { $result = Resolve-DnsName -Name $domain -ErrorAction SilentlyContinue if ($result) { Write-Host " [OK] $domain - Reachable" -ForegroundColor Green } else { Write-Host " [??] $domain - DNS resolution failed" -ForegroundColor Yellow } } catch { Write-Host " [!!] $domain - Cannot resolve" -ForegroundColor Red } } } # Main execution if (-not (Test-IsAdmin)) { Write-Host "[ERROR] This script requires Administrator privileges." -ForegroundColor Red Write-Host "Please run PowerShell as Administrator and try again." -ForegroundColor Yellow exit 1 } Write-Host "========================================" -ForegroundColor Cyan Write-Host " SolidWorks Telemetry Blocker" -ForegroundColor Cyan Write-Host " Atomaste Solution" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan if ($Undo) { Write-Host "`n[ACTION] Removing telemetry block..." -ForegroundColor Yellow if (Remove-SolidWorksBlock) { Write-Host "[OK] Telemetry block removed successfully" -ForegroundColor Green } else { Write-Host "[INFO] No telemetry block found to remove" -ForegroundColor Yellow } } else { Write-Host "`n[ACTION] Adding telemetry block..." -ForegroundColor Yellow Backup-HostsFile Add-SolidWorksBlock } Show-Status Write-Host "`n[DONE] Script completed." -ForegroundColor Green