Skip to content

Commit 3a92e37

Browse files
committed
Improve GPU detection and batch reliability
1 parent 07d6008 commit 3a92e37

2 files changed

Lines changed: 122 additions & 52 deletions

File tree

SystemTester.bat

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,14 @@ echo.
224224
pause
225225
echo.
226226
:: Call the PowerShell function for tool verification
227-
powershell -NoProfile -ExecutionPolicy Bypass -Command ". '%SCRIPT_PS1%'; Test-ToolVerification"
227+
powershell -NoProfile -ExecutionPolicy Bypass -Command "try { . '%SCRIPT_PS1%'; Test-ToolVerification; exit 0 } catch { Write-Error $_; exit 1 }"
228+
if errorlevel 1 (
229+
echo.
230+
echo [ERROR] Verification encountered an issue. Review output above.
231+
) else (
232+
echo.
233+
echo Verification complete.
234+
)
228235
echo.
229236
pause
230237
goto MENU
@@ -277,6 +284,13 @@ echo Extracting...
277284
if not exist "%SYSINT_DIR%" mkdir "%SYSINT_DIR%"
278285
powershell -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive -Path '%ZIP_FILE%' -DestinationPath '%SYSINT_DIR%' -Force; Write-Host 'Extracted successfully' -ForegroundColor Green"
279286

287+
if errorlevel 1 (
288+
echo [ERROR] Extraction failed. Remove any partial files and retry.
289+
if exist "%ZIP_FILE%" del "%ZIP_FILE%" 2>nul
290+
pause
291+
goto MENU
292+
)
293+
280294
del "%ZIP_FILE%" 2>nul
281295
echo.
282296
set "TOOL_COUNT=0"
@@ -297,6 +311,7 @@ echo.
297311
set "GPU_TOOLS_DIR=%SCRIPT_DIR%\Tools"
298312
set "GPUZ_PATH=%GPU_TOOLS_DIR%\GPU-Z.exe"
299313
set "GPUZ_URL=https://www.techpowerup.com/gpuz/"
314+
set "GPUZ_SIZE="
300315

301316
echo GPU Tools Directory: %GPU_TOOLS_DIR%
302317
echo.
@@ -314,7 +329,13 @@ echo --------------------------------------------------------
314329
echo INSTALLED TOOLS:
315330
echo --------------------------------------------------------
316331
if exist "%GPUZ_PATH%" (
317-
echo [OK] GPU-Z.exe - Installed
332+
for %%A in ("%GPUZ_PATH%") do set "GPUZ_SIZE=%%~zA"
333+
if not defined GPUZ_SIZE set "GPUZ_SIZE=0"
334+
if !GPUZ_SIZE! LSS 500000 (
335+
echo [!] GPU-Z.exe - File appears incomplete (!GPUZ_SIZE! bytes)
336+
) else (
337+
echo [OK] GPU-Z.exe - Installed (!GPUZ_SIZE! bytes)
338+
)
318339
) else (
319340
echo [ ] GPU-Z.exe - Not installed
320341
)
@@ -326,13 +347,11 @@ if exist "C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe" (
326347
)
327348

328349
:: Check for AMD tools
329-
set "AMD_FOUND="
330-
for %%R in ("HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000") do (
331-
reg query %%R /v DriverDesc 2>nul | find /i "AMD" >nul 2>&1
332-
if not errorlevel 1 set "AMD_FOUND=YES"
333-
)
334-
if defined AMD_FOUND (
335-
echo [OK] AMD GPU Drivers - Installed
350+
set "AMD_COUNT="
351+
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"
352+
if not defined AMD_COUNT set "AMD_COUNT=0"
353+
if not "!AMD_COUNT!"=="0" (
354+
echo [OK] AMD GPU Drivers - Detected (!AMD_COUNT! device^(s^))
336355
) else (
337356
echo [ ] AMD GPU Drivers - Not detected
338357
)
@@ -361,7 +380,14 @@ if exist "%GPUZ_PATH%" (
361380
echo GPU-Z is already installed at:
362381
echo %GPUZ_PATH%
363382
echo.
364-
for %%A in ("%GPUZ_PATH%") do echo Size: %%~zA bytes
383+
set "GPUZ_SIZE="
384+
for %%A in ("%GPUZ_PATH%") do set "GPUZ_SIZE=%%~zA"
385+
if not defined GPUZ_SIZE set "GPUZ_SIZE=0"
386+
echo Size: !GPUZ_SIZE! bytes
387+
if !GPUZ_SIZE! LSS 500000 (
388+
echo WARNING: File size is unusually small. Re-download recommended.
389+
echo.
390+
)
365391
echo.
366392
set /p "run_gpuz=Run GPU-Z now? (Y/N): "
367393
if /i "!run_gpuz!"=="Y" (
@@ -466,21 +492,16 @@ echo ========================================================
466492
echo.
467493

468494
:: Check for AMD GPU
469-
set "AMD_FOUND="
470-
set "AMD_NAME="
471-
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 (
472-
set "AMD_NAME=%%b"
473-
echo %%b | find /i "AMD" >nul 2>&1
474-
if not errorlevel 1 set "AMD_FOUND=YES"
475-
)
495+
set "AMD_COUNT="
496+
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"
497+
if not defined AMD_COUNT set "AMD_COUNT=0"
476498

477-
if defined AMD_FOUND (
478-
echo [OK] AMD GPU Detected: %AMD_NAME%
499+
if not "!AMD_COUNT!"=="0" (
500+
echo [OK] AMD GPU Detected: !AMD_COUNT! device^(s^)
479501
echo.
480502
echo AMD Driver Information:
481503
echo ========================================================
482-
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000" /v DriverVersion 2>nul
483-
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000" /v DriverDate 2>nul
504+
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 }; '' } }"
484505
echo ========================================================
485506
echo.
486507
echo NOTE: AMD doesn't provide a command-line tool like

SystemTester.ps1

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,21 @@ function Test-Trim {
570570
}
571571
$txt = $map.GetEnumerator() | ForEach-Object {
572572
$status = if ($_.Value -eq "0") { "Enabled" } else { "Disabled" }
573-
"$($_.Key): $status"
573+
"$($_.Key): TRIM $status"
574574
}
575575
if (-not $txt) { $txt = @("TRIM status unknown") }
576576

577+
if ($map.Count -gt 0) {
578+
$enabledCount = ($map.GetEnumerator() | Where-Object { $_.Value -eq "0" }).Count
579+
if ($enabledCount -eq $map.Count) {
580+
$txt += "Overall: TRIM is ENABLED"
581+
} elseif ($enabledCount -eq 0) {
582+
$txt += "Overall: TRIM is DISABLED"
583+
} else {
584+
$txt += "Overall: TRIM mixed (check per-filesystem status)"
585+
}
586+
}
587+
577588
$script:TestResults += @{
578589
Tool="SSD-TRIM"; Description="TRIM status"
579590
Status="SUCCESS"; Output=($txt -join "`n"); Duration=50
@@ -842,17 +853,25 @@ function Test-GPU {
842853
$gpus = Get-CimInstance Win32_VideoController
843854
foreach ($gpu in $gpus) {
844855
if ($gpu.Name) {
845-
$year = if ($gpu.DriverDate) {
846-
([DateTime]$gpu.DriverDate).Year
847-
} else {
848-
2020
856+
$driverYear = $null
857+
if ($gpu.DriverDate) {
858+
try {
859+
$driverYear = ([DateTime]$gpu.DriverDate).Year
860+
} catch {
861+
$driverYear = $null
862+
}
849863
}
850-
851-
$featureLevel = if ($year -ge 2020) { "12_x" }
852-
elseif ($year -ge 2016) { "12_0" }
853-
elseif ($year -ge 2012) { "11_0" }
864+
865+
if (-not $driverYear) {
866+
# Fall back to a conservative default if parsing fails
867+
$driverYear = 2014
868+
}
869+
870+
$featureLevel = if ($driverYear -ge 2020) { "12_x" }
871+
elseif ($driverYear -ge 2016) { "12_0" }
872+
elseif ($driverYear -ge 2012) { "11_0" }
854873
else { "10_x" }
855-
874+
856875
$capabilities += "$($gpu.Name): Likely supports DirectX $featureLevel"
857876
}
858877
}
@@ -907,23 +926,43 @@ function Test-GPUVendorSpecific {
907926

908927
# Check for AMD
909928
try {
910-
$amdRegistry = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000"
911-
912-
if (Test-Path $amdRegistry) {
913-
$amdInfo = Get-ItemProperty $amdRegistry -ErrorAction Stop
914-
915-
$amdOutput = @()
916-
$amdOutput += "AMD GPU Detected"
917-
$amdOutput += "Driver Description: $($amdInfo.DriverDesc)"
918-
$amdOutput += "Driver Version: $($amdInfo.DriverVersion)"
919-
$amdOutput += "Driver Date: $($amdInfo.DriverDate)"
920-
921-
if ($amdInfo.DriverDesc -match "AMD|Radeon") {
929+
$amdClassRoot = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}"
930+
931+
if (Test-Path $amdClassRoot) {
932+
$amdOutputs = @()
933+
$detected = $false
934+
935+
$subKeys = Get-ChildItem $amdClassRoot -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match "^\d{4}$" }
936+
foreach ($subKey in $subKeys) {
937+
try {
938+
$amdInfo = Get-ItemProperty $subKey.PSPath -ErrorAction Stop
939+
} catch {
940+
continue
941+
}
942+
943+
if ($amdInfo.DriverDesc -and $amdInfo.DriverDesc -match "AMD|Radeon") {
944+
$detected = $true
945+
$amdOutputs += "AMD GPU Slot $($subKey.PSChildName)"
946+
$amdOutputs += "Driver Description: $($amdInfo.DriverDesc)"
947+
if ($amdInfo.DeviceDesc) { $amdOutputs += "Device: $($amdInfo.DeviceDesc)" }
948+
if ($amdInfo.DriverVersion) { $amdOutputs += "Driver Version: $($amdInfo.DriverVersion)" }
949+
if ($amdInfo.DriverDate) { $amdOutputs += "Driver Date: $($amdInfo.DriverDate)" }
950+
$amdOutputs += ""
951+
}
952+
}
953+
954+
if ($detected) {
922955
$script:TestResults += @{
923956
Tool="AMD-GPU"; Description="AMD GPU information"
924-
Status="SUCCESS"; Output=($amdOutput -join "`n"); Duration=100
957+
Status="SUCCESS"; Output=($amdOutputs -join "`n"); Duration=150
925958
}
926959
Write-Host "AMD GPU information collected" -ForegroundColor Green
960+
} else {
961+
Write-Host "AMD GPU not detected" -ForegroundColor DarkGray
962+
$script:TestResults += @{
963+
Tool="AMD-GPU"; Description="AMD GPU information"
964+
Status="SKIPPED"; Output="No AMD GPU detected"; Duration=0
965+
}
927966
}
928967
} else {
929968
Write-Host "AMD GPU not detected" -ForegroundColor DarkGray
@@ -1052,6 +1091,8 @@ function Test-HardwareEvents {
10521091
function Test-WindowsUpdate {
10531092
Write-Host "`n=== Windows Update ===" -ForegroundColor Green
10541093
$updateSession = $null
1094+
$searcher = $null
1095+
$result = $null
10551096
try {
10561097
$lines = @()
10571098
try {
@@ -1080,6 +1121,12 @@ function Test-WindowsUpdate {
10801121
} catch {
10811122
Write-Host "Windows Update check failed" -ForegroundColor Yellow
10821123
} finally {
1124+
if ($result) {
1125+
try { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($result) | Out-Null } catch {}
1126+
}
1127+
if ($searcher) {
1128+
try { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($searcher) | Out-Null } catch {}
1129+
}
10831130
if ($updateSession) {
10841131
try { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($updateSession) | Out-Null } catch {}
10851132
}
@@ -1338,14 +1385,16 @@ function Generate-Report {
13381385

13391386
# === GPU HEALTH ===
13401387
if ($gpuDetails) {
1341-
if ($gpuDetails.Output -match "Driver Date:.*(\d{4})") {
1342-
$driverYear = [int]$matches[1]
1343-
$currentYear = (Get-Date).Year
1344-
if ($currentYear - $driverYear -gt 1) {
1345-
$recommendations += "• INFO: GPU drivers are over 1 year old"
1346-
$recommendations += " → Update to latest drivers for best performance"
1347-
$recommendations += " → NVIDIA: GeForce Experience or nvidia.com"
1348-
$recommendations += " → AMD: amd.com/en/support"
1388+
if ($gpuDetails.Output -match "Driver Date:.*?(\d{4})") {
1389+
$driverYear = 0
1390+
if ([int]::TryParse($matches[1], [ref]$driverYear)) {
1391+
$currentYear = (Get-Date).Year
1392+
if ($currentYear - $driverYear -gt 1) {
1393+
$recommendations += "• INFO: GPU drivers are over 1 year old"
1394+
$recommendations += " → Update to latest drivers for best performance"
1395+
$recommendations += " → NVIDIA: GeForce Experience or nvidia.com"
1396+
$recommendations += " → AMD: amd.com/en/support"
1397+
}
13491398
}
13501399
}
13511400
}

0 commit comments

Comments
 (0)