Skip to content

Commit 386d7dc

Browse files
authored
Improve GPU detection and batch reliability (#5)
1 parent 7f7666b commit 386d7dc

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
@@ -241,7 +241,14 @@ echo.
241241
pause
242242
echo.
243243
:: Call the PowerShell function for tool verification
244-
powershell -NoProfile -ExecutionPolicy Bypass -Command ". '%SCRIPT_PS1%'; Test-ToolVerification"
244+
powershell -NoProfile -ExecutionPolicy Bypass -Command "try { . '%SCRIPT_PS1%'; Test-ToolVerification; exit 0 } catch { Write-Error $_; exit 1 }"
245+
if errorlevel 1 (
246+
echo.
247+
echo [ERROR] Verification encountered an issue. Review output above.
248+
) else (
249+
echo.
250+
echo Verification complete.
251+
)
245252
echo.
246253
pause
247254
goto MENU
@@ -294,6 +301,13 @@ echo Extracting...
294301
if not exist "%SYSINT_DIR%" mkdir "%SYSINT_DIR%"
295302
powershell -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive -Path '%ZIP_FILE%' -DestinationPath '%SYSINT_DIR%' -Force; Write-Host 'Extracted successfully' -ForegroundColor Green"
296303

304+
if errorlevel 1 (
305+
echo [ERROR] Extraction failed. Remove any partial files and retry.
306+
if exist "%ZIP_FILE%" del "%ZIP_FILE%" 2>nul
307+
pause
308+
goto MENU
309+
)
310+
297311
del "%ZIP_FILE%" 2>nul
298312
echo.
299313
set "TOOL_COUNT=0"
@@ -314,6 +328,7 @@ echo.
314328
set "GPU_TOOLS_DIR=%SCRIPT_DIR%\Tools"
315329
set "GPUZ_PATH=%GPU_TOOLS_DIR%\GPU-Z.exe"
316330
set "GPUZ_URL=https://www.techpowerup.com/gpuz/"
331+
set "GPUZ_SIZE="
317332

318333
echo GPU Tools Directory: %GPU_TOOLS_DIR%
319334
echo.
@@ -331,7 +346,13 @@ echo --------------------------------------------------------
331346
echo INSTALLED TOOLS:
332347
echo --------------------------------------------------------
333348
if exist "%GPUZ_PATH%" (
334-
echo [OK] GPU-Z.exe - Installed
349+
for %%A in ("%GPUZ_PATH%") do set "GPUZ_SIZE=%%~zA"
350+
if not defined GPUZ_SIZE set "GPUZ_SIZE=0"
351+
if !GPUZ_SIZE! LSS 500000 (
352+
echo [!] GPU-Z.exe - File appears incomplete (!GPUZ_SIZE! bytes)
353+
) else (
354+
echo [OK] GPU-Z.exe - Installed (!GPUZ_SIZE! bytes)
355+
)
335356
) else (
336357
echo [ ] GPU-Z.exe - Not installed
337358
)
@@ -343,13 +364,11 @@ if exist "C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe" (
343364
)
344365

345366
:: Check for AMD tools
346-
set "AMD_FOUND="
347-
for %%R in ("HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000") do (
348-
reg query %%R /v DriverDesc 2>nul | find /i "AMD" >nul 2>&1
349-
if not errorlevel 1 set "AMD_FOUND=YES"
350-
)
351-
if defined AMD_FOUND (
352-
echo [OK] AMD GPU Drivers - Installed
367+
set "AMD_COUNT="
368+
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"
369+
if not defined AMD_COUNT set "AMD_COUNT=0"
370+
if not "!AMD_COUNT!"=="0" (
371+
echo [OK] AMD GPU Drivers - Detected (!AMD_COUNT! device^(s^))
353372
) else (
354373
echo [ ] AMD GPU Drivers - Not detected
355374
)
@@ -378,7 +397,14 @@ if exist "%GPUZ_PATH%" (
378397
echo GPU-Z is already installed at:
379398
echo %GPUZ_PATH%
380399
echo.
381-
for %%A in ("%GPUZ_PATH%") do echo Size: %%~zA bytes
400+
set "GPUZ_SIZE="
401+
for %%A in ("%GPUZ_PATH%") do set "GPUZ_SIZE=%%~zA"
402+
if not defined GPUZ_SIZE set "GPUZ_SIZE=0"
403+
echo Size: !GPUZ_SIZE! bytes
404+
if !GPUZ_SIZE! LSS 500000 (
405+
echo WARNING: File size is unusually small. Re-download recommended.
406+
echo.
407+
)
382408
echo.
383409
set /p "run_gpuz=Run GPU-Z now? (Y/N): "
384410
if /i "!run_gpuz!"=="Y" (
@@ -483,21 +509,16 @@ echo ========================================================
483509
echo.
484510

485511
:: Check for AMD GPU
486-
set "AMD_FOUND="
487-
set "AMD_NAME="
488-
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 (
489-
set "AMD_NAME=%%b"
490-
echo %%b | find /i "AMD" >nul 2>&1
491-
if not errorlevel 1 set "AMD_FOUND=YES"
492-
)
512+
set "AMD_COUNT="
513+
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"
514+
if not defined AMD_COUNT set "AMD_COUNT=0"
493515

494-
if defined AMD_FOUND (
495-
echo [OK] AMD GPU Detected: %AMD_NAME%
516+
if not "!AMD_COUNT!"=="0" (
517+
echo [OK] AMD GPU Detected: !AMD_COUNT! device^(s^)
496518
echo.
497519
echo AMD Driver Information:
498520
echo ========================================================
499-
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000" /v DriverVersion 2>nul
500-
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000" /v DriverDate 2>nul
521+
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 }; '' } }"
501522
echo ========================================================
502523
echo.
503524
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
@@ -699,10 +699,21 @@ function Test-Trim {
699699
}
700700
$txt = $map.GetEnumerator() | ForEach-Object {
701701
$status = if ($_.Value -eq "0") { "Enabled" } else { "Disabled" }
702-
"$($_.Key): $status"
702+
"$($_.Key): TRIM $status"
703703
}
704704
if (-not $txt) { $txt = @("TRIM status unknown") }
705705

706+
if ($map.Count -gt 0) {
707+
$enabledCount = ($map.GetEnumerator() | Where-Object { $_.Value -eq "0" }).Count
708+
if ($enabledCount -eq $map.Count) {
709+
$txt += "Overall: TRIM is ENABLED"
710+
} elseif ($enabledCount -eq 0) {
711+
$txt += "Overall: TRIM is DISABLED"
712+
} else {
713+
$txt += "Overall: TRIM mixed (check per-filesystem status)"
714+
}
715+
}
716+
706717
$script:TestResults += @{
707718
Tool="SSD-TRIM"; Description="TRIM status"
708719
Status="SUCCESS"; Output=($txt -join "`n"); Duration=50
@@ -971,17 +982,25 @@ function Test-GPU {
971982
$gpus = Get-CimInstance Win32_VideoController
972983
foreach ($gpu in $gpus) {
973984
if ($gpu.Name) {
974-
$year = if ($gpu.DriverDate) {
975-
([DateTime]$gpu.DriverDate).Year
976-
} else {
977-
2020
985+
$driverYear = $null
986+
if ($gpu.DriverDate) {
987+
try {
988+
$driverYear = ([DateTime]$gpu.DriverDate).Year
989+
} catch {
990+
$driverYear = $null
991+
}
978992
}
979-
980-
$featureLevel = if ($year -ge 2020) { "12_x" }
981-
elseif ($year -ge 2016) { "12_0" }
982-
elseif ($year -ge 2012) { "11_0" }
993+
994+
if (-not $driverYear) {
995+
# Fall back to a conservative default if parsing fails
996+
$driverYear = 2014
997+
}
998+
999+
$featureLevel = if ($driverYear -ge 2020) { "12_x" }
1000+
elseif ($driverYear -ge 2016) { "12_0" }
1001+
elseif ($driverYear -ge 2012) { "11_0" }
9831002
else { "10_x" }
984-
1003+
9851004
$capabilities += "$($gpu.Name): Likely supports DirectX $featureLevel"
9861005
}
9871006
}
@@ -1036,23 +1055,43 @@ function Test-GPUVendorSpecific {
10361055

10371056
# Check for AMD
10381057
try {
1039-
$amdRegistry = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000"
1040-
1041-
if (Test-Path $amdRegistry) {
1042-
$amdInfo = Get-ItemProperty $amdRegistry -ErrorAction Stop
1043-
1044-
$amdOutput = @()
1045-
$amdOutput += "AMD GPU Detected"
1046-
$amdOutput += "Driver Description: $($amdInfo.DriverDesc)"
1047-
$amdOutput += "Driver Version: $($amdInfo.DriverVersion)"
1048-
$amdOutput += "Driver Date: $($amdInfo.DriverDate)"
1049-
1050-
if ($amdInfo.DriverDesc -match "AMD|Radeon") {
1058+
$amdClassRoot = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}"
1059+
1060+
if (Test-Path $amdClassRoot) {
1061+
$amdOutputs = @()
1062+
$detected = $false
1063+
1064+
$subKeys = Get-ChildItem $amdClassRoot -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match "^\d{4}$" }
1065+
foreach ($subKey in $subKeys) {
1066+
try {
1067+
$amdInfo = Get-ItemProperty $subKey.PSPath -ErrorAction Stop
1068+
} catch {
1069+
continue
1070+
}
1071+
1072+
if ($amdInfo.DriverDesc -and $amdInfo.DriverDesc -match "AMD|Radeon") {
1073+
$detected = $true
1074+
$amdOutputs += "AMD GPU Slot $($subKey.PSChildName)"
1075+
$amdOutputs += "Driver Description: $($amdInfo.DriverDesc)"
1076+
if ($amdInfo.DeviceDesc) { $amdOutputs += "Device: $($amdInfo.DeviceDesc)" }
1077+
if ($amdInfo.DriverVersion) { $amdOutputs += "Driver Version: $($amdInfo.DriverVersion)" }
1078+
if ($amdInfo.DriverDate) { $amdOutputs += "Driver Date: $($amdInfo.DriverDate)" }
1079+
$amdOutputs += ""
1080+
}
1081+
}
1082+
1083+
if ($detected) {
10511084
$script:TestResults += @{
10521085
Tool="AMD-GPU"; Description="AMD GPU information"
1053-
Status="SUCCESS"; Output=($amdOutput -join "`n"); Duration=100
1086+
Status="SUCCESS"; Output=($amdOutputs -join "`n"); Duration=150
10541087
}
10551088
Write-Host "AMD GPU information collected" -ForegroundColor Green
1089+
} else {
1090+
Write-Host "AMD GPU not detected" -ForegroundColor DarkGray
1091+
$script:TestResults += @{
1092+
Tool="AMD-GPU"; Description="AMD GPU information"
1093+
Status="SKIPPED"; Output="No AMD GPU detected"; Duration=0
1094+
}
10561095
}
10571096
} else {
10581097
Write-Host "AMD GPU not detected" -ForegroundColor DarkGray
@@ -1181,6 +1220,8 @@ function Test-HardwareEvents {
11811220
function Test-WindowsUpdate {
11821221
Write-Host "`n=== Windows Update ===" -ForegroundColor Green
11831222
$updateSession = $null
1223+
$searcher = $null
1224+
$result = $null
11841225
try {
11851226
$lines = @()
11861227
try {
@@ -1226,6 +1267,12 @@ function Test-WindowsUpdate {
12261267
} catch {
12271268
Write-Host "Windows Update check failed" -ForegroundColor Yellow
12281269
} finally {
1270+
if ($result) {
1271+
try { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($result) | Out-Null } catch {}
1272+
}
1273+
if ($searcher) {
1274+
try { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($searcher) | Out-Null } catch {}
1275+
}
12291276
if ($updateSession) {
12301277
try { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($updateSession) | Out-Null } catch {}
12311278
}
@@ -1533,14 +1580,16 @@ function Generate-Report {
15331580

15341581
# === GPU HEALTH ===
15351582
if ($gpuDetails) {
1536-
if ($gpuDetails.Output -match "Driver Date:.*(\d{4})") {
1537-
$driverYear = [int]$matches[1]
1538-
$currentYear = (Get-Date).Year
1539-
if ($currentYear - $driverYear -gt 1) {
1540-
$recommendations += "• INFO: GPU drivers are over 1 year old"
1541-
$recommendations += " → Update to latest drivers for best performance"
1542-
$recommendations += " → NVIDIA: GeForce Experience or nvidia.com"
1543-
$recommendations += " → AMD: amd.com/en/support"
1583+
if ($gpuDetails.Output -match "Driver Date:.*?(\d{4})") {
1584+
$driverYear = 0
1585+
if ([int]::TryParse($matches[1], [ref]$driverYear)) {
1586+
$currentYear = (Get-Date).Year
1587+
if ($currentYear - $driverYear -gt 1) {
1588+
$recommendations += "• INFO: GPU drivers are over 1 year old"
1589+
$recommendations += " → Update to latest drivers for best performance"
1590+
$recommendations += " → NVIDIA: GeForce Experience or nvidia.com"
1591+
$recommendations += " → AMD: amd.com/en/support"
1592+
}
15441593
}
15451594
}
15461595
}

0 commit comments

Comments
 (0)