Created
October 30, 2024 23:46
-
-
Save blizzardengle/0a70447195dc6f15ff40ad154ffd80aa to your computer and use it in GitHub Desktop.
Windows HTTP & Print Spooler Port Conflict Resolution: This script ensures that port 80 remains open for other applications by moving the default Windows Print Service to a different port.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Windows HTTP and Print Spooler Port Conflict Resolution Script | |
.DESCRIPTION | |
This script resolves port conflicts between Docker/Web services and the Windows Print Spooler | |
by reconfiguring the HTTP service to use port 5000 instead of 80. This allows both printing | |
and Docker to work simultaneously. | |
.NOTES | |
- Must be run as Administrator | |
- Creates a log file in Downloads folder | |
- Will forcefully stop and restart printing services | |
- Recommended to save any open documents before running | |
.INSTRUCTIONS | |
1. Save this file as Fix-PrinterConflict.ps1 | |
2. Right-click the file and select "Run with PowerShell" | |
3. If prompted, choose "Yes" to run as Administrator | |
4. Check output for any errors | |
5. Test both printing and Docker after completion | |
.AUTHOR | |
Created via Anthropic Claude | |
#> | |
# Log file in Downloads folder | |
$logPath = Join-Path ([Environment]::GetFolderPath("UserProfile")) "Downloads\printer_fix_log.txt" | |
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" | |
function Write-LogAndConsole { | |
param($message) | |
$logMessage = "[$timestamp] $message" | |
Write-Host $logMessage | |
Add-Content -Path $logPath -Value $logMessage | |
} | |
try { | |
Write-LogAndConsole "=== Starting printer service reconfiguration ===" | |
# Backup current HTTP service settings | |
Write-LogAndConsole "Backing up HTTP service settings..." | |
$httpService = Get-Service -Name "HTTP" | |
$spoolerService = Get-Service -Name "Spooler" | |
$originalHTTPStartType = $httpService.StartType | |
# Force stop all related services | |
Write-LogAndConsole "Stopping dependent services..." | |
Stop-Service -Name "Spooler" -Force -ErrorAction SilentlyContinue | |
Stop-Service -Name "HTTP" -Force -ErrorAction SilentlyContinue | |
# Clear all HTTP listeners | |
Write-LogAndConsole "Clearing HTTP listeners..." | |
netsh http delete iplisten ipaddress=* | Out-Null | |
netsh http delete urlacl url=http://*:80/ | Out-Null | |
# Configure HTTP to only use localhost on port 5000 | |
Write-LogAndConsole "Configuring HTTP for localhost:5000..." | |
netsh http add iplisten ipaddress=127.0.0.1 | Out-Null | |
netsh http add urlacl url=http://127.0.0.1:5000/ user=Everyone | Out-Null | |
# Update registry to change HTTP port | |
Write-LogAndConsole "Updating registry settings..." | |
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Services\HTTP\Parameters" | |
if (!(Test-Path $regPath)) { | |
New-Item -Path $regPath -Force | Out-Null | |
} | |
Set-ItemProperty -Path $regPath -Name "ListenPort" -Value 5000 -Type DWord -Force | |
# Enable and start services | |
Write-LogAndConsole "Starting services..." | |
Set-Service -Name "HTTP" -StartupType Manual | |
Set-Service -Name "Spooler" -StartupType Automatic | |
Start-Service -Name "HTTP" -ErrorAction Continue | |
Start-Sleep -Seconds 2 | |
Start-Service -Name "Spooler" -ErrorAction Continue | |
# Verify status | |
$httpStatus = Get-Service -Name "HTTP" | Select-Object Status | |
$spoolerStatus = Get-Service -Name "Spooler" | Select-Object Status | |
Write-LogAndConsole "Final Status:" | |
Write-LogAndConsole "HTTP Service: $($httpStatus.Status)" | |
Write-LogAndConsole "Print Spooler: $($spoolerStatus.Status)" | |
# Show current listeners | |
Write-LogAndConsole "Current HTTP listeners:" | |
netsh http show iplisten | |
} catch { | |
Write-LogAndConsole "ERROR: $_" | |
# Emergency rollback | |
Write-LogAndConsole "Attempting emergency recovery..." | |
Set-Service -Name "HTTP" -StartupType $originalHTTPStartType | |
Start-Service -Name "HTTP" -ErrorAction SilentlyContinue | |
Start-Service -Name "Spooler" -ErrorAction SilentlyContinue | |
} | |
Write-LogAndConsole "=== Script completed. Check $logPath for details ===" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment