@echo off
:: ============================================================================
:: CyberHighway-SelfService.bat - One-Click Windows Clean, Update & Security Scan
:: Published by Cyber Highway LTD (https://www.cyberhighway.co.uk)
:: Bedfordshire | 07378 510 974 | info@cyberhighway.co.uk
::
:: Double-click to run. Automatically requests Administrator permission,
:: cleans temporary junk & Recycle Bin, updates Microsoft Defender definitions,
:: runs a malware scan, checks disk health & system files (DISM & SFC),
:: triggers a Windows Update check, and opens a full Service Completion Report
:: saved directly to your Desktop.
:: ============================================================================
setlocal
set "SELF=%~f0"
set "WORKDIR=%~dp0"
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
"$c = Get-Content -LiteralPath $env:SELF -Raw; $i = $c.LastIndexOf('<# :POWERSHELL_PAYLOAD #>'); if ($i -lt 0) { Write-Error 'Payload not found'; exit 1 }; $ps = $c.Substring($i); Invoke-Expression $ps"
exit /b %ERRORLEVEL%
<# :POWERSHELL_PAYLOAD #>
$ErrorActionPreference = 'Continue'
$batchPath = $env:SELF
# 1. Self-elevate as Administrator if not already running elevated
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host 'Requesting Administrator permission...' -ForegroundColor Yellow
Start-Process -FilePath 'cmd.exe' -ArgumentList "/c `"`"$batchPath`"`"" -Verb RunAs
exit
}
$Host.UI.RawUI.WindowTitle = 'Cyber Highway LTD - Self-Service Clean, Update & Security Check'
Clear-Host
Write-Host '==========================================================================' -ForegroundColor DarkGreen
Write-Host ' CYBER HIGHWAY LTD - ONE-CLICK SELF-SERVICE PC CARE' -ForegroundColor Green
Write-Host ' Automated Malware Scan, Cleanup, System Repair & Update Check' -ForegroundColor Cyan
Write-Host '==========================================================================' -ForegroundColor DarkGreen
Write-Host ''
Write-Host ' IMPORTANT NOTICE:' -ForegroundColor Yellow
Write-Host ' - This tool will empty the Recycle Bin, remove temporary/cache files,'
Write-Host ' update Microsoft Defender, scan for threats, and check system files.'
Write-Host ' - Ensure you have backed up important files before continuing.'
Write-Host ' - No security scan guarantees a 100% virus-free computer.'
Write-Host ''
Read-Host ' Press ENTER to start the automated service (or close this window to cancel)'
Write-Host ''
$startTime = Get-Date
$desktopPath = [Environment]::GetFolderPath('Desktop')
if (-not (Test-Path -LiteralPath $desktopPath)) {
$desktopPath = $env:USERPROFILE
}
function Get-FreeSpaceGB([string]$Drive = 'C') {
try {
return [math]::Round((Get-PSDrive -Name $Drive -ErrorAction Stop).Free / 1GB, 2)
} catch {
return 0.0
}
}
function Get-TotalSpaceGB([string]$Drive = 'C') {
try {
$d = Get-PSDrive -Name $Drive -ErrorAction Stop
return [math]::Round(($d.Used + $d.Free) / 1GB, 2)
} catch {
return 0.0
}
}
$freeBeforeGB = Get-FreeSpaceGB 'C'
$totalDriveGB = Get-TotalSpaceGB 'C'
$osInfo = try { (Get-CimInstance Win32_OperatingSystem -ErrorAction Stop).Caption } catch { 'Microsoft Windows' }
# ============================================================================
# STEP 1: MICROSOFT DEFENDER UPDATE & MALWARE SCAN
# ============================================================================
Write-Host '[Step 1 of 4] Updating Microsoft Defender & running Malware Scan...' -ForegroundColor Cyan
$defenderResult = [ordered]@{
Active = $false
SignaturesUpdated = 'No'
SignatureVersion = 'Unknown'
ScanCompleted = 'No'
ThreatsDetected = 0
ThreatDetails = @()
Notes = ''
}
try {
$mpStatus = Get-MpComputerStatus -ErrorAction Stop
$defenderResult.Active = [bool]$mpStatus.AntivirusEnabled
if ($defenderResult.Active) {
Write-Host ' -> Updating Microsoft Defender security intelligence definitions...' -ForegroundColor Gray
try {
Update-MpSignature -ErrorAction Stop
$defenderResult.SignaturesUpdated = 'Yes (Updated to latest)'
} catch {
$defenderResult.SignaturesUpdated = 'Using existing local definitions'
}
$mpAfter = Get-MpComputerStatus -ErrorAction SilentlyContinue
if ($mpAfter) {
$defenderResult.SignatureVersion = [string]$mpAfter.AntivirusSignatureVersion
}
Write-Host ' -> Running Microsoft Defender Quick Malware Scan (please wait)...' -ForegroundColor Gray
Start-MpScan -ScanType QuickScan -ErrorAction Stop
$defenderResult.ScanCompleted = 'Completed (Quick Scan)'
$threats = Get-MpThreatDetection -ErrorAction SilentlyContinue |
Where-Object { $_.InitialDetectionTime -ge $startTime.AddMinutes(-10) }
if ($threats) {
$detList = foreach ($t in $threats) {
[pscustomobject]@{
ThreatID = $t.ThreatID
Cleaned = $t.ActionSuccess
Resources = ($t.Resources -join '; ')
}
}
$defenderResult.ThreatDetails = @($detList)
$defenderResult.ThreatsDetected = @($detList).Count
}
$defenderResult.Notes = if ($defenderResult.ThreatsDetected -eq 0) { 'No active threats detected during scan.' } else { "$($defenderResult.ThreatsDetected) detection(s) logged - review details below." }
} else {
$defenderResult.Notes = 'Microsoft Defender is not the active antivirus on this PC.'
}
} catch {
$defenderResult.Notes = "Defender check note: $($_.Exception.Message)"
}
# ============================================================================
# STEP 2: SYSTEM CLEANUP (TEMP FILES, CACHE, RECYCLE BIN, DNS)
# ============================================================================
Write-Host '[Step 2 of 4] Cleaning temporary files, caches & Recycle Bin...' -ForegroundColor Cyan
$cleanupRows = New-Object System.Collections.Generic.List[object]
function Clear-SafeFolder([string]$Label, [string]$FolderPath, [string]$Filter = '*') {
if (-not (Test-Path -LiteralPath $FolderPath)) { return }
$files = Get-ChildItem -LiteralPath $FolderPath -Filter $Filter -Recurse -Force -File -ErrorAction SilentlyContinue
$countBefore = ($files | Measure-Object).Count
$bytesBefore = [int64](($files | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum)
Get-ChildItem -LiteralPath $FolderPath -Filter $Filter -Force -ErrorAction SilentlyContinue | ForEach-Object {
Remove-Item -LiteralPath $_.FullName -Recurse -Force -ErrorAction SilentlyContinue
}
$rem = Get-ChildItem -LiteralPath $FolderPath -Filter $Filter -Recurse -Force -File -ErrorAction SilentlyContinue
$bytesAfter = [int64](($rem | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum)
$freedMB = [math]::Max(0, [math]::Round(($bytesBefore - $bytesAfter) / 1MB, 2))
$cleanupRows.Add([pscustomobject]@{
Area = $Label
Files = $countBefore
FreedMB = $freedMB
Status = 'Cleaned'
})
}
Clear-SafeFolder 'User Temp Folder (%TEMP%)' $env:TEMP
Clear-SafeFolder 'Windows System Temp (C:\Windows\Temp)' "$env:WINDIR\Temp"
Clear-SafeFolder 'Windows Prefetch Cache' "$env:WINDIR\Prefetch"
Clear-SafeFolder 'Windows Error Reporting Reports' "$env:ProgramData\Microsoft\Windows\WER\ReportArchive"
Clear-SafeFolder 'Windows Error Reporting Queue' "$env:ProgramData\Microsoft\Windows\WER\ReportQueue"
Clear-SafeFolder 'Explorer Thumbnail Cache' "$env:LOCALAPPDATA\Microsoft\Windows\Explorer" 'thumbcache_*.db'
# Windows Update download cache
$wuPath = "$env:WINDIR\SoftwareDistribution\Download"
if (Test-Path -LiteralPath $wuPath) {
Stop-Service -Name wuauserv -Force -ErrorAction SilentlyContinue
Stop-Service -Name bits -Force -ErrorAction SilentlyContinue
Clear-SafeFolder 'Windows Update Download Cache' $wuPath
Start-Service -Name bits -ErrorAction SilentlyContinue
Start-Service -Name wuauserv -ErrorAction SilentlyContinue
}
# Recycle Bin
try {
$rbFiles = Get-ChildItem -LiteralPath 'C:\$Recycle.Bin' -Recurse -Force -File -ErrorAction SilentlyContinue
$rbCount = ($rbFiles | Measure-Object).Count
$rbMB = [math]::Round(([int64](($rbFiles | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum)) / 1MB, 2)
Clear-RecycleBin -Force -ErrorAction SilentlyContinue
$cleanupRows.Add([pscustomobject]@{
Area = 'Windows Recycle Bin'
Files = $rbCount
FreedMB = $rbMB
Status = 'Emptied'
})
} catch {}
# Flush DNS cache
ipconfig.exe /flushdns | Out-Null
$cleanupRows.Add([pscustomobject]@{
Area = 'DNS Resolver Cache'
Files = 0
FreedMB = 0.0
Status = 'Flushed'
})
# ============================================================================
# STEP 3: DISK HEALTH, SYSTEM FILE REPAIR (DISM & SFC) & SSD OPTIMISATION
# ============================================================================
Write-Host '[Step 3 of 4] Checking Disk Health, System Files (DISM & SFC) & SSD Trim...' -ForegroundColor Cyan
$diskSummary = @()
try {
$disks = Get-PhysicalDisk -ErrorAction Stop
foreach ($d in $disks) {
$diskSummary += [pscustomobject]@{
Disk = $d.FriendlyName
Type = [string]$d.MediaType
Health = [string]$d.HealthStatus
Status = [string]$d.OperationalStatus
SizeGB = [math]::Round($d.Size / 1GB, 1)
}
}
} catch {}
Write-Host ' -> Running DISM system image health check...' -ForegroundColor Gray
$dismStatus = 'Checked'
try {
& DISM.exe /Online /Cleanup-Image /CheckHealth | Out-Null
$dismStatus = if ($LASTEXITCODE -eq 0) { 'Healthy (No component store corruption detected)' } else { "Completed (Code $LASTEXITCODE)" }
} catch {
$dismStatus = 'Skipped'
}
Write-Host ' -> Running System File Checker (sfc /scannow - this may take a few minutes)...' -ForegroundColor Gray
$sfcStatus = 'Checked'
try {
& sfc.exe /scannow | Out-Null
$sfcStatus = if ($LASTEXITCODE -eq 0) { 'Verified (System files checked & repaired if needed)' } else { "Completed (Code $LASTEXITCODE)" }
} catch {
$sfcStatus = 'Skipped'
}
$ssdStatus = 'Not required'
try {
$hasSsd = $diskSummary | Where-Object { $_.Type -eq 'SSD' }
if ($hasSsd) {
Write-Host ' -> Re-trimming SSD storage...' -ForegroundColor Gray
Optimize-Volume -DriveLetter C -ReTrim -ErrorAction Stop | Out-Null
$ssdStatus = 'Optimised (SSD Re-Trim completed on C:)'
} else {
$ssdStatus = 'Standard drive / No SSD trim required'
}
} catch {
$ssdStatus = 'Standard drive optimisation skipped'
}
# ============================================================================
# STEP 4: WINDOWS UPDATE CHECK & PENDING RESTART CHECK
# ============================================================================
Write-Host '[Step 4 of 4] Triggering Windows Update check & checking restart status...' -ForegroundColor Cyan
$wuTriggered = 'Checked'
try {
$uso = "$env:WINDIR\System32\UsoClient.exe"
if (Test-Path -LiteralPath $uso) {
Start-Process -FilePath $uso -ArgumentList 'StartScan' -WindowStyle Hidden -ErrorAction SilentlyContinue
$wuTriggered = 'Windows Update background scan triggered'
}
} catch {}
$pendingReasons = @()
if (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending') {
$pendingReasons += 'Windows Component Servicing'
}
if (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') {
$pendingReasons += 'Windows Update'
}
$rebootNeeded = if ($pendingReasons.Count -gt 0) { "Yes - Restart recommended ($($pendingReasons -join ', '))" } else { 'No pending restart required' }
$freeAfterGB = Get-FreeSpaceGB 'C'
$totalFreedMB = [math]::Round((($cleanupRows | Measure-Object -Property FreedMB -Sum).Sum), 2)
$durationMin = [math]::Max(0.1, [math]::Round(((Get-Date) - $startTime).TotalMinutes, 1))
$reportTimeStr = Get-Date -Format 'dd MMM yyyy HH:mm:ss'
$fileStamp = Get-Date -Format 'yyyy-MM-dd_HHmm'
# ============================================================================
# GENERATE COMPLETION REPORTS ON DESKTOP (HTML + TXT) & OPEN AUTOMATICALLY
# ============================================================================
$htmlReportPath = Join-Path $desktopPath "CyberHighway-Service-Report_$fileStamp.html"
$txtReportPath = Join-Path $desktopPath "CyberHighway-Service-Report_$fileStamp.txt"
$cleanupHtmlRows = ($cleanupRows | ForEach-Object {
"
| $($_.Area) | $($_.Files) | $($_.FreedMB) MB | $($_.Status) |
"
}) -join "`n"
$diskHtmlRows = if ($diskSummary.Count -gt 0) {
($diskSummary | ForEach-Object {
"| $($_.Disk) | $($_.Type) | $($_.SizeGB) GB | $($_.Health) ($($_.Status)) |
"
}) -join "`n"
} else {
"| Standard Windows Volume (C: $totalDriveGB GB) |
"
}
$htmlContent = @"
Cyber Highway LTD — PC Service Completion Report ($env:COMPUTERNAME)
Cyber Highway LTD · Self-Service Completion Report
Windows Clean, Update & Security Check Report
Malware Scan Result$($defenderResult.ThreatsDetected) Threats Found
Junk & Cache Cleaned$totalFreedMB MB Freed
C: Drive Free Space$freeBeforeGB GB → $freeAfterGB GB
Time Elapsed$durationMin mins
1. Microsoft Defender Malware Scan
| Check | Result |
| Microsoft Defender Active | $($defenderResult.Active) |
| Security Intelligence Definitions | $($defenderResult.SignaturesUpdated) (Version: $($defenderResult.SignatureVersion)) |
| Malware Scan Status | $($defenderResult.ScanCompleted) |
| Threats Detected | $($defenderResult.ThreatsDetected) — $($defenderResult.Notes) |
2. System Cleanup & Space Reclaimed
| Cleanup Category | Files Processed | Space Reclaimed | Status |
$cleanupHtmlRows
3. Disk Health, System File Repair & Windows Update
| Maintenance Task | Status |
| DISM Component Store Check | $dismStatus |
| System File Checker (SFC /scannow) | $sfcStatus |
| SSD Storage Optimisation (TRIM) | $ssdStatus |
| Windows Update Scan | $wuTriggered |
| Pending Restart Check | $rebootNeeded |
4. Physical Disk Health
| Drive | Media Type | Capacity | Health Status |
$diskHtmlRows
"@
$txtContent = @"
==========================================================================
CYBER HIGHWAY LTD - SELF-SERVICE COMPLETION REPORT
==========================================================================
Computer Name : $env:COMPUTERNAME
Operating Sys : $osInfo
Completed At : $reportTimeStr
Duration : $durationMin minutes
1. MICROSOFT DEFENDER MALWARE SCAN
- Defender Active : $($defenderResult.Active)
- Definitions Updated : $($defenderResult.SignaturesUpdated) ($($defenderResult.SignatureVersion))
- Scan Completed : $($defenderResult.ScanCompleted)
- Threats Detected : $($defenderResult.ThreatsDetected) ($($defenderResult.Notes))
2. SYSTEM CLEANUP & FREE SPACE
- Space Reclaimed : $totalFreedMB MB
- C: Free Space : $freeBeforeGB GB -> $freeAfterGB GB
3. SYSTEM REPAIR & WINDOWS UPDATE CHECK
- DISM Check : $dismStatus
- SFC /scannow : $sfcStatus
- SSD Optimisation : $ssdStatus
- Windows Update : $wuTriggered
- Restart Needed : $rebootNeeded
Need further support? Contact Cyber Highway LTD:
Phone: 07378 510 974 | Email: info@cyberhighway.co.uk | https://www.cyberhighway.co.uk
==========================================================================
"@
Set-Content -LiteralPath $htmlReportPath -Value $htmlContent -Encoding UTF8
Set-Content -LiteralPath $txtReportPath -Value $txtContent -Encoding UTF8
Write-Host ''
Write-Host '==========================================================================' -ForegroundColor DarkGreen
Write-Host ' ALL TASKS COMPLETED SUCCESSFULLY!' -ForegroundColor Green
Write-Host '==========================================================================' -ForegroundColor DarkGreen
Write-Host (" Threats Detected : {0}" -f $defenderResult.ThreatsDetected) -ForegroundColor Cyan
Write-Host (" Junk Cleaned : {0} MB freed" -f $totalFreedMB) -ForegroundColor Cyan
Write-Host (" C: Free Space : {0} GB -> {1} GB" -f $freeBeforeGB, $freeAfterGB) -ForegroundColor Cyan
Write-Host (" Restart Needed : {0}" -f $rebootNeeded) -ForegroundColor Cyan
Write-Host ''
Write-Host (" Report saved to Desktop: {0}" -f $htmlReportPath) -ForegroundColor Green
Write-Host ' Opening your Service Completion Report now...' -ForegroundColor Yellow
Start-Process $htmlReportPath
Write-Host ''
Read-Host ' Press ENTER to close this window'