diff --git a/SystemTester.bat b/SystemTester.bat index 5489d6f..4f5498d 100644 --- a/SystemTester.bat +++ b/SystemTester.bat @@ -224,7 +224,14 @@ echo. pause echo. :: Call the PowerShell function for tool verification -powershell -NoProfile -ExecutionPolicy Bypass -Command ". '%SCRIPT_PS1%'; Test-ToolVerification" +powershell -NoProfile -ExecutionPolicy Bypass -Command "try { . '%SCRIPT_PS1%'; Test-ToolVerification; exit 0 } catch { Write-Error $_; exit 1 }" +if errorlevel 1 ( + echo. + echo [ERROR] Verification encountered an issue. Review output above. +) else ( + echo. + echo Verification complete. +) echo. pause goto MENU @@ -277,6 +284,13 @@ echo Extracting... if not exist "%SYSINT_DIR%" mkdir "%SYSINT_DIR%" powershell -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive -Path '%ZIP_FILE%' -DestinationPath '%SYSINT_DIR%' -Force; Write-Host 'Extracted successfully' -ForegroundColor Green" +if errorlevel 1 ( + echo [ERROR] Extraction failed. Remove any partial files and retry. + if exist "%ZIP_FILE%" del "%ZIP_FILE%" 2>nul + pause + goto MENU +) + del "%ZIP_FILE%" 2>nul echo. set "TOOL_COUNT=0" @@ -297,6 +311,7 @@ echo. set "GPU_TOOLS_DIR=%SCRIPT_DIR%\Tools" set "GPUZ_PATH=%GPU_TOOLS_DIR%\GPU-Z.exe" set "GPUZ_URL=https://www.techpowerup.com/gpuz/" +set "GPUZ_SIZE=" echo GPU Tools Directory: %GPU_TOOLS_DIR% echo. @@ -314,7 +329,13 @@ echo -------------------------------------------------------- echo INSTALLED TOOLS: echo -------------------------------------------------------- if exist "%GPUZ_PATH%" ( - echo [OK] GPU-Z.exe - Installed + for %%A in ("%GPUZ_PATH%") do set "GPUZ_SIZE=%%~zA" + if not defined GPUZ_SIZE set "GPUZ_SIZE=0" + if !GPUZ_SIZE! LSS 500000 ( + echo [!] GPU-Z.exe - File appears incomplete (!GPUZ_SIZE! bytes) + ) else ( + echo [OK] GPU-Z.exe - Installed (!GPUZ_SIZE! bytes) + ) ) else ( echo [ ] GPU-Z.exe - Not installed ) @@ -326,13 +347,11 @@ if exist "C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe" ( ) :: Check for AMD tools -set "AMD_FOUND=" -for %%R in ("HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000") do ( - reg query %%R /v DriverDesc 2>nul | find /i "AMD" >nul 2>&1 - if not errorlevel 1 set "AMD_FOUND=YES" -) -if defined AMD_FOUND ( - echo [OK] AMD GPU Drivers - Installed +set "AMD_COUNT=" +for /f %%A in ('powershell -NoProfile -Command "(Get-ChildItem 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}' -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match '^\d{4}$' } | ForEach-Object { Get-ItemProperty $_.PsPath -ErrorAction SilentlyContinue } | Where-Object { $_.DriverDesc -match 'AMD|Radeon' }).Count" 2^>nul') do set "AMD_COUNT=%%A" +if not defined AMD_COUNT set "AMD_COUNT=0" +if not "!AMD_COUNT!"=="0" ( + echo [OK] AMD GPU Drivers - Detected (!AMD_COUNT! device^(s^)) ) else ( echo [ ] AMD GPU Drivers - Not detected ) @@ -361,7 +380,14 @@ if exist "%GPUZ_PATH%" ( echo GPU-Z is already installed at: echo %GPUZ_PATH% echo. - for %%A in ("%GPUZ_PATH%") do echo Size: %%~zA bytes + set "GPUZ_SIZE=" + for %%A in ("%GPUZ_PATH%") do set "GPUZ_SIZE=%%~zA" + if not defined GPUZ_SIZE set "GPUZ_SIZE=0" + echo Size: !GPUZ_SIZE! bytes + if !GPUZ_SIZE! LSS 500000 ( + echo WARNING: File size is unusually small. Re-download recommended. + echo. + ) echo. set /p "run_gpuz=Run GPU-Z now? (Y/N): " if /i "!run_gpuz!"=="Y" ( @@ -466,21 +492,16 @@ echo ======================================================== echo. :: Check for AMD GPU -set "AMD_FOUND=" -set "AMD_NAME=" -for /f "tokens=2*" %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000" /v DriverDesc 2^>nul ^| find "DriverDesc"') do ( - set "AMD_NAME=%%b" - echo %%b | find /i "AMD" >nul 2>&1 - if not errorlevel 1 set "AMD_FOUND=YES" -) +set "AMD_COUNT=" +for /f %%A in ('powershell -NoProfile -Command "(Get-ChildItem 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}' -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match '^\d{4}$' } | ForEach-Object { Get-ItemProperty $_.PsPath -ErrorAction SilentlyContinue } | Where-Object { $_.DriverDesc -match 'AMD|Radeon' }).Count" 2^>nul') do set "AMD_COUNT=%%A" +if not defined AMD_COUNT set "AMD_COUNT=0" -if defined AMD_FOUND ( - echo [OK] AMD GPU Detected: %AMD_NAME% +if not "!AMD_COUNT!"=="0" ( + echo [OK] AMD GPU Detected: !AMD_COUNT! device^(s^) echo. echo AMD Driver Information: echo ======================================================== - reg query "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000" /v DriverVersion 2>nul - reg query "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000" /v DriverDate 2>nul + powershell -NoProfile -Command "Get-ChildItem 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}' -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match '^\d{4}$' } | ForEach-Object { $info = Get-ItemProperty $_.PsPath -ErrorAction SilentlyContinue; if ($info.DriverDesc -match 'AMD|Radeon') { '{0}: {1}' -f $_.PSChildName,$info.DriverDesc; if ($info.DriverVersion) { ' Driver Version: {0}' -f $info.DriverVersion }; if ($info.DriverDate) { ' Driver Date: {0}' -f $info.DriverDate }; '' } }" echo ======================================================== echo. echo NOTE: AMD doesn't provide a command-line tool like diff --git a/SystemTester.ps1 b/SystemTester.ps1 index d6f69ff..7268da7 100644 --- a/SystemTester.ps1 +++ b/SystemTester.ps1 @@ -570,10 +570,21 @@ function Test-Trim { } $txt = $map.GetEnumerator() | ForEach-Object { $status = if ($_.Value -eq "0") { "Enabled" } else { "Disabled" } - "$($_.Key): $status" + "$($_.Key): TRIM $status" } if (-not $txt) { $txt = @("TRIM status unknown") } + if ($map.Count -gt 0) { + $enabledCount = ($map.GetEnumerator() | Where-Object { $_.Value -eq "0" }).Count + if ($enabledCount -eq $map.Count) { + $txt += "Overall: TRIM is ENABLED" + } elseif ($enabledCount -eq 0) { + $txt += "Overall: TRIM is DISABLED" + } else { + $txt += "Overall: TRIM mixed (check per-filesystem status)" + } + } + $script:TestResults += @{ Tool="SSD-TRIM"; Description="TRIM status" Status="SUCCESS"; Output=($txt -join "`n"); Duration=50 @@ -842,17 +853,25 @@ function Test-GPU { $gpus = Get-CimInstance Win32_VideoController foreach ($gpu in $gpus) { if ($gpu.Name) { - $year = if ($gpu.DriverDate) { - ([DateTime]$gpu.DriverDate).Year - } else { - 2020 + $driverYear = $null + if ($gpu.DriverDate) { + try { + $driverYear = ([DateTime]$gpu.DriverDate).Year + } catch { + $driverYear = $null + } } - - $featureLevel = if ($year -ge 2020) { "12_x" } - elseif ($year -ge 2016) { "12_0" } - elseif ($year -ge 2012) { "11_0" } + + if (-not $driverYear) { + # Fall back to a conservative default if parsing fails + $driverYear = 2014 + } + + $featureLevel = if ($driverYear -ge 2020) { "12_x" } + elseif ($driverYear -ge 2016) { "12_0" } + elseif ($driverYear -ge 2012) { "11_0" } else { "10_x" } - + $capabilities += "$($gpu.Name): Likely supports DirectX $featureLevel" } } @@ -907,23 +926,43 @@ function Test-GPUVendorSpecific { # Check for AMD try { - $amdRegistry = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000" - - if (Test-Path $amdRegistry) { - $amdInfo = Get-ItemProperty $amdRegistry -ErrorAction Stop - - $amdOutput = @() - $amdOutput += "AMD GPU Detected" - $amdOutput += "Driver Description: $($amdInfo.DriverDesc)" - $amdOutput += "Driver Version: $($amdInfo.DriverVersion)" - $amdOutput += "Driver Date: $($amdInfo.DriverDate)" - - if ($amdInfo.DriverDesc -match "AMD|Radeon") { + $amdClassRoot = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}" + + if (Test-Path $amdClassRoot) { + $amdOutputs = @() + $detected = $false + + $subKeys = Get-ChildItem $amdClassRoot -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match "^\d{4}$" } + foreach ($subKey in $subKeys) { + try { + $amdInfo = Get-ItemProperty $subKey.PSPath -ErrorAction Stop + } catch { + continue + } + + if ($amdInfo.DriverDesc -and $amdInfo.DriverDesc -match "AMD|Radeon") { + $detected = $true + $amdOutputs += "AMD GPU Slot $($subKey.PSChildName)" + $amdOutputs += "Driver Description: $($amdInfo.DriverDesc)" + if ($amdInfo.DeviceDesc) { $amdOutputs += "Device: $($amdInfo.DeviceDesc)" } + if ($amdInfo.DriverVersion) { $amdOutputs += "Driver Version: $($amdInfo.DriverVersion)" } + if ($amdInfo.DriverDate) { $amdOutputs += "Driver Date: $($amdInfo.DriverDate)" } + $amdOutputs += "" + } + } + + if ($detected) { $script:TestResults += @{ Tool="AMD-GPU"; Description="AMD GPU information" - Status="SUCCESS"; Output=($amdOutput -join "`n"); Duration=100 + Status="SUCCESS"; Output=($amdOutputs -join "`n"); Duration=150 } Write-Host "AMD GPU information collected" -ForegroundColor Green + } else { + Write-Host "AMD GPU not detected" -ForegroundColor DarkGray + $script:TestResults += @{ + Tool="AMD-GPU"; Description="AMD GPU information" + Status="SKIPPED"; Output="No AMD GPU detected"; Duration=0 + } } } else { Write-Host "AMD GPU not detected" -ForegroundColor DarkGray @@ -1052,6 +1091,8 @@ function Test-HardwareEvents { function Test-WindowsUpdate { Write-Host "`n=== Windows Update ===" -ForegroundColor Green $updateSession = $null + $searcher = $null + $result = $null try { $lines = @() try { @@ -1080,6 +1121,12 @@ function Test-WindowsUpdate { } catch { Write-Host "Windows Update check failed" -ForegroundColor Yellow } finally { + if ($result) { + try { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($result) | Out-Null } catch {} + } + if ($searcher) { + try { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($searcher) | Out-Null } catch {} + } if ($updateSession) { try { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($updateSession) | Out-Null } catch {} } @@ -1338,14 +1385,16 @@ function Generate-Report { # === GPU HEALTH === if ($gpuDetails) { - if ($gpuDetails.Output -match "Driver Date:.*(\d{4})") { - $driverYear = [int]$matches[1] - $currentYear = (Get-Date).Year - if ($currentYear - $driverYear -gt 1) { - $recommendations += "• INFO: GPU drivers are over 1 year old" - $recommendations += " → Update to latest drivers for best performance" - $recommendations += " → NVIDIA: GeForce Experience or nvidia.com" - $recommendations += " → AMD: amd.com/en/support" + if ($gpuDetails.Output -match "Driver Date:.*?(\d{4})") { + $driverYear = 0 + if ([int]::TryParse($matches[1], [ref]$driverYear)) { + $currentYear = (Get-Date).Year + if ($currentYear - $driverYear -gt 1) { + $recommendations += "• INFO: GPU drivers are over 1 year old" + $recommendations += " → Update to latest drivers for best performance" + $recommendations += " → NVIDIA: GeForce Experience or nvidia.com" + $recommendations += " → AMD: amd.com/en/support" + } } } }