# Windows 7 Embedded Standard Cleanup Script - Fixed Version
# Requires Administrator privileges
# Check for Administrator rights
if (-NOT ([Security.Principal.WindowsPrincipal]
[Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.Wi
ndowsBuiltInRole] "Administrator")) {
Write-Host "This script requires Administrator privileges. Please run as
Administrator."
pause
exit
}
# Disable UAC
Write-Host "Disabling UAC..."
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\
System" -Name "EnableLUA" -Value 0 -ErrorAction SilentlyContinue
# Disable hibernation
Write-Host "Disabling hibernation..."
powercfg -h off 2>&1 | Out-Null
# Disable System Restore
Write-Host "Disabling System Restore..."
Disable-ComputerRestore -Drive "C:\" -ErrorAction SilentlyContinue
# Clean temporary files
Write-Host "Cleaning temporary files..."
Remove-Item -Path "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "C:\Windows\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "$env:SystemRoot\Prefetch\*" -Recurse -Force -ErrorAction
SilentlyContinue
# Clean update cache (with better error handling)
Write-Host "Cleaning update cache..."
try {
Stop-Service -Name "wuauserv" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "$env:SystemRoot\SoftwareDistribution\Download\*" -Recurse -
Force -ErrorAction SilentlyContinue
Start-Service -Name "wuauserv" -ErrorAction SilentlyContinue
}
catch {
Write-Host "Update service could not be restarted. You may need to reboot to
complete update cache cleanup." -ForegroundColor Yellow
}
# Disable unnecessary services (with existence checks)
Write-Host "Disabling unnecessary services..."
$servicesToDisable = @(
"Fax",
"TrkWks",
"WMPNetworkSvc",
"WSearch",
"RemoteRegistry",
"ShellHWDetection",
"TabletInputService",
"WerSvc"
)
foreach ($service in $servicesToDisable) {
if (Get-Service -Name $service -ErrorAction SilentlyContinue) {
try {
Stop-Service -Name $service -Force -ErrorAction SilentlyContinue
Set-Service -Name $service -StartupType Disabled -ErrorAction
SilentlyContinue
Write-Host "Disabled $service"
}
catch {
Write-Host "Could not disable $service" -ForegroundColor Yellow
}
}
}
# Remove only features that exist in Embedded version
Write-Host "Removing unnecessary features..."
$featuresToRemove = @(
"Printing-XPSServices-Features",
"WindowsGadgetPlatform"
)
foreach ($feature in $featuresToRemove) {
try {
dism /online /Disable-Feature /FeatureName:$feature /NoRestart /Quiet
Write-Host "Attempted to remove $feature"
}
catch {
Write-Host "Feature $feature not found or could not be removed" -
ForegroundColor Yellow
}
}
# Optimize page file
Write-Host "Optimizing page file..."
try {
$System = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges
if ($System.AutomaticManagedPagefile) {
$System.AutomaticManagedPagefile = $false
$System.Put()
}
$CurrentPageFile = Get-WmiObject Win32_PageFileSetting
$CurrentPageFile.Delete()
Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{Name="C:\
pagefile.sys"; InitialSize=1024; MaximumSize=2048} -ErrorAction SilentlyContinue
}
catch {
Write-Host "Could not optimize page file settings" -ForegroundColor Yellow
}
# Optimize UI performance
Write-Host "Optimizing UI performance..."
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "MenuShowDelay" -Value
"0" -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "AutoEndTasks" -Value
"1" -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "HungAppTimeout" -Value
"1000" -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "WaitToKillAppTimeout" -
Value "2000" -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control" -Name
"WaitToKillServiceTimeout" -Value "2000" -ErrorAction SilentlyContinue
# Disable visual effects
Write-Host "Disabling visual effects..."
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\
VisualEffects" -Name "VisualFXSetting" -Value 2 -ErrorAction SilentlyContinue
# Run disk cleanup
Write-Host "Running disk cleanup..."
Start-Process -FilePath "cleanmgr" -ArgumentList "/sagerun:1" -WindowStyle Hidden -
Wait
Write-Host "Cleanup completed. System reboot is recommended." -ForegroundColor
Green
pause