if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host "You need to run this script as an administrator!" -ForegroundColor Red exit }
Write-Host "Starting the extreme RAM optimization script..." -ForegroundColor Yellow
Write-Host "Optimizing kernel-level memory handling and paging..." -ForegroundColor Yellow $memoryManagementPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
New-ItemProperty -Path $memoryManagementPath -Name "DisablePagingExecutive" -Value 1 -Force
New-ItemProperty -Path $memoryManagementPath -Name "LargeSystemCache" -Value 0 -Force
New-ItemProperty -Path $memoryManagementPath -Name "IoPageLockLimit" -Value 0xFFFFFFFF -Force
New-ItemProperty -Path $memoryManagementPath -Name "ClearPageFileAtShutdown" -Value 1 -Force
New-ItemProperty -Path $memoryManagementPath -Name "SystemCacheWorkingSetSize" -Value 0xFFFFFFFF -Force
Write-Host "Disabling unnecessary services..." -ForegroundColor Yellow $services = @( "SysMain", "WSearch", "DiagTrack", "DoSvc", "Fax", "XblAuthManager", "WMPNetworkSvc", "Spooler", "MapsBroker", "BluetoothUserService", "RetailDemo", "IKEEXT", "OneSyncSvc", "BcastDVRUserService", "MessagingService", "TabletInputService", "NetTcpPortSharing", "SmsRouter", "BiSvc" )
foreach ($service in $services) { # Check if the service exists before trying to disable it if (Get-Service -Name $service -ErrorAction SilentlyContinue) { Set-Service -Name $service -StartupType Disabled Stop-Service -Name $service -Force Write-Host "Disabled $service service" -ForegroundColor Green } else { Write-Host "Service $service not found on this system." -ForegroundColor Red } }
Write-Host "Tweaking memory management settings..." -ForegroundColor Yellow
$prefetchPath = "$memoryManagementPath\PrefetchParameters" New-ItemProperty -Path $prefetchPath -Name "EnablePrefetcher" -Value 0 -Force New-ItemProperty -Path $prefetchPath -Name "EnableSuperfetch" -Value 0 -Force
New-ItemProperty -Path $memoryManagementPath -Name "StandbyMemoryListPriority" -Value 0 -Force
New-ItemProperty -Path $memoryManagementPath -Name "CompressionEnabled" -Value 1 -Force
if (Get-Command Set-MpPreference -ErrorAction SilentlyContinue) { Set-MpPreference -DisableRealtimeMonitoring $true } else { Write-Host "Windows Defender module not available. Skipping real-time monitoring disablement." -ForegroundColor Yellow }
Write-Host "Disabling visual effects and animations..." -ForegroundColor Yellow
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects" -Name "VisualFXSetting" -Value 2 -Force
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "UserPreferencesMask" -Value 90,12,03,80,10,00,00,00 -Force Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "MenuShowDelay" -Value 0 -Force Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "DragFullWindows" -Value 0 -Force New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" -Name "EnableTransparency" -Value 0 -Force
Write-Host "Optimizing virtual memory settings..." -ForegroundColor Yellow
New-ItemProperty -Path $memoryManagementPath -Name "PagingFiles" -Value "C:\pagefile.sys 1024 2048" -Force
Write-Host "Disabling background apps and telemetry..." -ForegroundColor Yellow
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy" -Name "LetAppsRunInBackground" -Value 2 -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name "AllowTelemetry" -Value 0 -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name "Disabled" -Value 1 -Force
Write-Host "Applying final tweaks..." -ForegroundColor Yellow
$tipsPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" New-ItemProperty -Path $tipsPath -Name "SoftLandingEnabled" -Value 0 -Force New-ItemProperty -Path $tipsPath -Name "SubscribedContent-338389Enabled" -Value 0 -Force
$serializePath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Serialize" New-Item -Path $serializePath -Force | Out-Null New-ItemProperty -Path $serializePath -Name "StartupDelayInMSec" -Value 0 -Force
Write-Host "Extreme RAM optimization complete. Reboot your system for all changes to take effect." -ForegroundColor Green