Files
SERVtomaste/Solidworks Licenses/scripts/02-disable-services.ps1
Anto01 57bcfa4a9a Add Solidworks licenses, scripts, and update server docs
- Add Solidworks license files and install guides
- Add PowerShell privacy lockdown scripts for Solidworks telemetry
- Add Siemens License Server v5.1 binary for NX
- Update DALIDOU-SERVER.md with storage layout, backup system, and DNS fixes
- Add MEGA-PLAN-BRAIN-SYSTEM.md for unified knowledge management
- Add Claude Code local settings

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 11:56:23 -05:00

234 lines
7.4 KiB
PowerShell

#Requires -RunAsAdministrator
<#
.SYNOPSIS
Disables non-essential SolidWorks background services.
.DESCRIPTION
Identifies and disables SolidWorks update and background services
that are not required for core functionality or licensing.
.NOTES
Author: Atomaste Solution
Requires: Administrator privileges
Saves original service states before modification
#>
param(
[switch]$Undo, # Restore original service states
[switch]$ListOnly # Only list services, don't modify
)
$stateFile = "$env:USERPROFILE\solidworks-services-backup.json"
# Services to disable (update/background services)
$servicesToDisable = @(
"SOLIDWORKS Update Publisher Service",
"SolidWorks Background Downloader",
"SOLIDWORKS Flexnet Server",
"3DExperience*"
)
# Services to KEEP enabled (required for licensing)
$servicesToKeep = @(
"SolidNetWork License Manager",
"SOLIDWORKS SolidNetWork License Manager"
)
function Test-IsAdmin {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Get-SolidWorksServices {
$allServices = @()
# Find all SOLIDWORKS-related services
$swServices = Get-Service -DisplayName "*SOLIDWORKS*" -ErrorAction SilentlyContinue
$dsServices = Get-Service -DisplayName "*3DEXPERIENCE*" -ErrorAction SilentlyContinue
$dassaultServices = Get-Service -DisplayName "*Dassault*" -ErrorAction SilentlyContinue
if ($swServices) { $allServices += $swServices }
if ($dsServices) { $allServices += $dsServices }
if ($dassaultServices) { $allServices += $dassaultServices }
return $allServices | Sort-Object -Property DisplayName -Unique
}
function Save-ServiceStates {
param([array]$Services)
$states = @{}
foreach ($svc in $Services) {
$states[$svc.Name] = @{
DisplayName = $svc.DisplayName
Status = $svc.Status.ToString()
StartType = $svc.StartType.ToString()
}
}
$states | ConvertTo-Json -Depth 3 | Set-Content -Path $stateFile -Force
Write-Host "[OK] Service states saved to: $stateFile" -ForegroundColor Green
}
function Restore-ServiceStates {
if (-not (Test-Path $stateFile)) {
Write-Host "[ERROR] No backup file found: $stateFile" -ForegroundColor Red
return $false
}
$states = Get-Content -Path $stateFile -Raw | ConvertFrom-Json
foreach ($serviceName in $states.PSObject.Properties.Name) {
$originalState = $states.$serviceName
try {
$svc = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
if ($svc) {
Set-Service -Name $serviceName -StartupType $originalState.StartType -ErrorAction Stop
Write-Host "[OK] Restored $($originalState.DisplayName) to $($originalState.StartType)" -ForegroundColor Green
}
} catch {
Write-Host "[WARN] Could not restore $serviceName : $_" -ForegroundColor Yellow
}
}
return $true
}
function Test-ShouldDisable {
param([string]$DisplayName)
# Check if it's a service to keep
foreach ($keep in $servicesToKeep) {
if ($DisplayName -like "*$keep*") {
return $false
}
}
# Check if it matches services to disable
foreach ($disable in $servicesToDisable) {
if ($DisplayName -like "*$disable*") {
return $true
}
}
# Default: check if it contains "update", "background", "download"
if ($DisplayName -match "update|background|download|telemetry") {
return $true
}
return $false
}
function Show-Services {
$services = Get-SolidWorksServices
Write-Host "`n=== SOLIDWORKS RELATED SERVICES ===" -ForegroundColor Cyan
if ($services.Count -eq 0) {
Write-Host "[INFO] No SOLIDWORKS services found on this system" -ForegroundColor Yellow
return @()
}
Write-Host "`nFound $($services.Count) service(s):" -ForegroundColor White
foreach ($svc in $services) {
$shouldDisable = Test-ShouldDisable -DisplayName $svc.DisplayName
$statusColor = switch ($svc.Status) {
"Running" { "Green" }
"Stopped" { "Gray" }
default { "Yellow" }
}
$startTypeColor = switch ($svc.StartType) {
"Disabled" { "Red" }
"Manual" { "Yellow" }
"Automatic" { "Green" }
default { "White" }
}
Write-Host ""
Write-Host " $($svc.DisplayName)" -ForegroundColor White
Write-Host " Name: $($svc.Name)" -ForegroundColor Gray
Write-Host " Status: " -NoNewline; Write-Host "$($svc.Status)" -ForegroundColor $statusColor
Write-Host " StartType: " -NoNewline; Write-Host "$($svc.StartType)" -ForegroundColor $startTypeColor
if ($shouldDisable) {
Write-Host " Recommendation: " -NoNewline
Write-Host "DISABLE (update/telemetry service)" -ForegroundColor Red
} else {
Write-Host " Recommendation: " -NoNewline
Write-Host "KEEP (may be required)" -ForegroundColor Green
}
}
return $services
}
function Disable-TelemetryServices {
$services = Get-SolidWorksServices
if ($services.Count -eq 0) {
Write-Host "[INFO] No SOLIDWORKS services to disable" -ForegroundColor Yellow
return
}
# Save current states first
Save-ServiceStates -Services $services
$disabled = 0
$kept = 0
foreach ($svc in $services) {
$shouldDisable = Test-ShouldDisable -DisplayName $svc.DisplayName
if ($shouldDisable) {
try {
# Stop service if running
if ($svc.Status -eq "Running") {
Stop-Service -Name $svc.Name -Force -ErrorAction Stop
Write-Host "[OK] Stopped: $($svc.DisplayName)" -ForegroundColor Yellow
}
# Disable service
Set-Service -Name $svc.Name -StartupType Disabled -ErrorAction Stop
Write-Host "[OK] Disabled: $($svc.DisplayName)" -ForegroundColor Green
$disabled++
} catch {
Write-Host "[ERROR] Failed to disable $($svc.DisplayName): $_" -ForegroundColor Red
}
} else {
Write-Host "[KEEP] Preserved: $($svc.DisplayName)" -ForegroundColor Cyan
$kept++
}
}
Write-Host "`n[SUMMARY] Disabled: $disabled | Kept: $kept" -ForegroundColor White
}
# Main execution
if (-not (Test-IsAdmin)) {
Write-Host "[ERROR] This script requires Administrator privileges." -ForegroundColor Red
exit 1
}
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " SolidWorks Service Manager" -ForegroundColor Cyan
Write-Host " Atomaste Solution" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
if ($ListOnly) {
Show-Services
Write-Host "`n[INFO] Use without -ListOnly to apply changes" -ForegroundColor Yellow
} elseif ($Undo) {
Write-Host "`n[ACTION] Restoring original service states..." -ForegroundColor Yellow
Restore-ServiceStates
} else {
Write-Host "`n[ACTION] Scanning and disabling update/telemetry services..." -ForegroundColor Yellow
Show-Services
Write-Host ""
Disable-TelemetryServices
}
Write-Host "`n[DONE] Script completed." -ForegroundColor Green