Advertisement
JacobPaulin

Get Device Information

Mar 16th, 2023
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Winbatch 12.78 KB | None | 0 0
  1. @echo off
  2.  
  3. title Device Information
  4. cls
  5.  
  6. for /f "tokens=2 delims==" %%i in ('"WMIC cpu get name /format:list"') do set sysInfo_cpu_name=%%i
  7. for /f "tokens=2 delims==" %%i in ('"WMIC cpu get threadcount /format:list"') do set sysInfo_cpu_threadCount=%%i
  8. for /f "tokens=2 delims==" %%i in ('"WMIC cpu get numberofcores /format:list"') do set sysInfo_cpu_numberOfCores=%%i
  9. for /f "tokens=2 delims==" %%i in ('"WMIC bios get SerialNumber /format:list"') do set sysInfo_bios_serialNumber=%%i
  10. for /f "tokens=2 delims==" %%i in ('"WMIC bios get Version /format:list"') do set sysInfo_bios_version=%%i
  11. for /f "tokens=2 delims==" %%i in ('"WMIC computersystem get name /format:list"') do set sysInfo_computerSystem_name=%%i
  12. for /f "tokens=2 delims==" %%i in ('"WMIC computersystem get SystemFamily /format:list"') do set sysInfo_computerSystem_systemFamily=%%i
  13. for /f "tokens=2 delims==" %%i in ('"WMIC computersystem get SystemType /format:list"') do set sysInfo_computerSystem_systemType=%%i
  14. for /f "tokens=2 delims==" %%i in ('"WMIC os get Caption /format:list"') do set sysInfo_os_caption=%%i
  15. for /f "tokens=2 delims==" %%i in ('"WMIC os get BuildNumber /format:list"') do set sysInfo_os_buildNumber=%%i
  16. for /f "tokens=2 delims==" %%i in ('"WMIC os get Version /format:list"') do set sysInfo_os_version=%%i
  17. for /f "usebackq tokens=1 delims=" %%i in (`PowerShell -command "(GWMI Win32_PhysicalMemory|Measure Capacity -Sum).Sum/1MB"`) do set sysInfo_ram_totalMB=%%i MB
  18. for /f "tokens=2 delims==" %%i in ('"WMIC memorychip get Speed /format:list"') do set sysInfo_ram_clockSpeed=%%i MHz
  19. for /f "tokens=1-3" %%n in ('"WMIC /node:"localhost" logicaldisk get Name,Size,FreeSpace | find /i "C:""') do (
  20.     @SETLOCAL ENABLEEXTENSIONS
  21.     @SETLOCAL ENABLEDELAYEDEXPANSION
  22.    
  23.     set FreeBytes=%%n & set TotalBytes=%%p
  24.     set TotalGB=0
  25.     set FreeGB=0
  26.     set gbConvertVal=1074
  27.  
  28.     set /a TotalSpace=!TotalBytes:~0,-6! / !gbConvertVal!
  29.     set /a FreeSpace=!FreeBytes:~0,-7! / !gbConvertVal!
  30.  
  31.     set TotalGB=!TotalSpace!
  32.     set FreeGB=!FreeSpace!
  33.  
  34.     set /A TotalUsed=!TotalSpace! - !FreeSpace!
  35.     set /A MULTIUSED=!TotalUsed!*100
  36.     set /A PERCENTUSED=!MULTIUSED!/!TotalGB!
  37.    
  38.     set sysInfo_disk_totalSpace=!TotalGB! GB
  39.     set sysInfo_disk_freeSpace=!FreeGB! GB
  40.     set sysInfo_disk_percentUsed=!PERCENTUSED!%%
  41. )
  42.  
  43.  
  44. @rem Find longest Line
  45. set /a longestLineLength=0
  46.  
  47. @rem Test Line 2
  48.     set /a testNumber=0
  49.     call :strlen testNumberLen sysInfo_computerSystem_name
  50.     set /a testNumber=%testNumberLen% + 37
  51.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  52.  
  53. @rem Test Line 4
  54.     set /a testNumber=0
  55.     call :strlen testNumber sysInfo_computerSystem_name
  56.     set /a testNumber=%testNumber% + 25
  57.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  58.  
  59. @rem Test Line 5
  60.     set /a testNumber=0
  61.     call :strlen testNumber sysInfo_computerSystem_systemFamily
  62.     set /a testNumber=%testNumber% + 25
  63.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  64.  
  65. @rem Test Line 6
  66.     set /a testNumber=0
  67.     call :strlen testNumber sysInfo_bios_serialNumber
  68.     set /a testNumber=%testNumber% + 25
  69.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  70.  
  71. @rem Test Line 7
  72.     set /a testNumber=0
  73.     call :strlen testNumber sysInfo_bios_version
  74.     set /a testNumber=%testNumber% + 25
  75.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  76.  
  77. @rem Test Line 8
  78.     set /a testNumber=0
  79.     call :strlen testNumber sysInfo_os_caption
  80.     set /a testNumber=%testNumber% + 25
  81.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  82.  
  83. @rem Test Line 9
  84.     set /a testNumber=0
  85.     call :strlen testNumber sysInfo_os_buildNumber
  86.     set /a testNumber=%testNumber% + 25
  87.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  88.  
  89. @rem Test Line 10
  90.     set /a testNumber=0
  91.     call :strlen testNumber sysInfo_os_version
  92.     set /a testNumber=%testNumber% + 25
  93.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  94.  
  95. @rem Test Line 11
  96.     set /a testNumber=0
  97.     call :strlen testNumber sysInfo_computerSystem_systemType
  98.     set /a testNumber=%testNumber% + 25
  99.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  100.  
  101. @rem Test Line 12
  102.     call set "sysInfo_cpu_name=%%sysInfo_cpu_name:(=^(%%"
  103.     call set "sysInfo_cpu_name=%%sysInfo_cpu_name:)=^)%%"
  104.     set /a testNumber=0
  105.     call :strlen testNumber sysInfo_cpu_name
  106.     set /a testNumber=%testNumber% + 25
  107.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  108.  
  109. @rem Test Line 13
  110.     set /a testNumber=0
  111.     call :strlen testNumber sysInfo_cpu_threadCount
  112.     set /a testNumber=%testNumber% + 25
  113.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  114.  
  115. @rem Test Line 14
  116.     set /a testNumber=0
  117.     call :strlen testNumber sysInfo_cpu_numberOfCores
  118.     set /a testNumber=%testNumber% + 25
  119.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  120.  
  121. @rem Test Line 15
  122.     set /a testNumber=0
  123.     call :strlen testNumber sysInfo_ram_totalMB
  124.     set /a testNumber=%testNumber% + 25
  125.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  126.  
  127. @rem Test Line 16
  128.     set /a testNumber=0
  129.     call :strlen testNumber sysInfo_ram_clockSpeed
  130.     set /a testNumber=%testNumber% + 25
  131.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  132.  
  133. @rem Test Line 17
  134.     set /a testNumber=0
  135.     call :strlen testNumber sysInfo_disk_totalSpace
  136.     set /a testNumber=%testNumber% + 25
  137.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  138.  
  139. @rem Test Line 18
  140.     set /a testNumber=0
  141.     call :strlen testNumber sysInfo_disk_freeSpace
  142.     set /a testNumber=%testNumber% + 25
  143.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  144.  
  145. @rem Test Line 19
  146.     set /a testNumber=0
  147.     call :strlen testNumber sysInfo_disk_percentUsed
  148.     set /a testNumber=%testNumber% + 25
  149.     if %testNumber% gtr %longestLineLength% set /a longestLineLength=%testNumber%
  150.  
  151. @rem LINE 1
  152.     set printLine_1=----------------------------------------------------------------------------------------------------------------------------------------------------
  153.     call set printLine_1=%%printLine_1:~0,%longestLineLength%%%
  154.     echo +-%printLine_1%-+
  155.  
  156. @rem LINE 2
  157.     @rem Min 37, Max 52 (before space and line on each end)
  158.     set printLine_2=System Info ^For Device %sysInfo_computerSystem_name%                                                                                                  
  159.     call set printLine_2=%%printLine_2:~0,%longestLineLength%%%
  160.     echo ^| %printLine_2% ^|
  161.  
  162. @rem LINE 3
  163.     set printLine_3=----------------------------------------------------------------------------------------------------------------------------------------------------
  164.     call set printLine_3=%%printLine_3:~0,%longestLineLength%%%
  165.     echo +-%printLine_3%-+
  166.  
  167. @rem LINE 4
  168.     set printLine_4=Device Name:             %sysInfo_computerSystem_name%                                                                                                  
  169.     call set printLine_4=%%printLine_4:~0,%longestLineLength%%%
  170.     echo ^| %printLine_4% ^|
  171.  
  172. @rem LINE 5
  173.     set printLine_5=Device Model:            %sysInfo_computerSystem_systemFamily%                                                                                                  
  174.     call set printLine_5=%%printLine_5:~0,%longestLineLength%%%
  175.     echo ^| %printLine_5% ^|
  176.  
  177. @rem LINE 6
  178.     set printLine_6=Device Serial Number:    %sysInfo_bios_serialNumber%                                                                                                  
  179.     call set printLine_6=%%printLine_6:~0,%longestLineLength%%%
  180.     echo ^| %printLine_6% ^|
  181.  
  182. @rem LINE 7
  183.     set printLine_7=BIOS Version:            %sysInfo_bios_version%                                                                                                  
  184.     call set printLine_7=%%printLine_7:~0,%longestLineLength%%%
  185.     echo ^| %printLine_7% ^|
  186.  
  187. @rem LINE 8
  188.     set printLine_8=Windows Edition:         %sysInfo_os_caption%                                                                                                  
  189.     call set printLine_8=%%printLine_8:~0,%longestLineLength%%%
  190.     echo ^| %printLine_8% ^|
  191.  
  192. @rem LINE 9
  193.     set printLine_9=Windows Build:           %sysInfo_os_buildNumber%                                                                                                  
  194.     call set printLine_9=%%printLine_9:~0,%longestLineLength%%%
  195.     echo ^| %printLine_9% ^|
  196.  
  197. @rem LINE 10
  198.     set printLine_10=Windows Version:         %sysInfo_os_version%                                                                                                  
  199.     call set printLine_10=%%printLine_10:~0,%longestLineLength%%%
  200.     echo ^| %printLine_10% ^|
  201.  
  202. @rem LINE 11
  203.     set printLine_11=System Architecture:     %sysInfo_computerSystem_systemType%                                                                                                  
  204.     call set printLine_11=%%printLine_11:~0,%longestLineLength%%%
  205.     echo ^| %printLine_11% ^|
  206.  
  207. @rem LINE 12
  208.     call set "sysInfo_cpu_name=%%sysInfo_cpu_name:^(=(%%"
  209.     call set "sysInfo_cpu_name=%%sysInfo_cpu_name:^)=)%%"
  210.     set printLine_12=CPU Model:               %sysInfo_cpu_name%                                                                                                  
  211.     call set printLine_12=%%printLine_12:~0,%longestLineLength%%%
  212.     echo ^| %printLine_12% ^|
  213.  
  214. @rem LINE 13
  215.     set printLine_13=CPU Threads:             %sysInfo_cpu_threadCount%                                                                                                  
  216.     call set printLine_13=%%printLine_13:~0,%longestLineLength%%%
  217.     echo ^| %printLine_13% ^|
  218.  
  219. @rem LINE 14
  220.     set printLine_14=CPU Cores:               %sysInfo_cpu_numberOfCores%                                                                                                  
  221.     call set printLine_14=%%printLine_14:~0,%longestLineLength%%%
  222.     echo ^| %printLine_14% ^|
  223.  
  224. @rem LINE 15
  225.     set printLine_15=Total RAM:               %sysInfo_ram_totalMB%                                                                                                  
  226.     call set printLine_15=%%printLine_15:~0,%longestLineLength%%%
  227.     echo ^| %printLine_15% ^|
  228.  
  229. @rem LINE 16
  230.     set printLine_16=RAM Clock Speed:         %sysInfo_ram_clockSpeed%                                                                                                  
  231.     call set printLine_16=%%printLine_16:~0,%longestLineLength%%%
  232.     echo ^| %printLine_16% ^|
  233.  
  234. @rem LINE 17
  235.     set printLine_17=Total Disk Space ^(C:^):   %sysInfo_disk_totalSpace%                                                                                                  
  236.     call set printLine_17=%%printLine_17:~0,%longestLineLength%%%
  237.     echo ^| %printLine_17% ^|
  238.  
  239. @rem LINE 18
  240.     set printLine_18=Free Disk Space ^(C:^):    %sysInfo_disk_freeSpace%                                                                                                  
  241.     call set printLine_18=%%printLine_18:~0,%longestLineLength%%%
  242.     echo ^| %printLine_18% ^|
  243.  
  244. @rem LINE 19
  245.     set printLine_19=Used Disk Space ^(C:^):    %sysInfo_disk_percentUsed%                                                                                                  
  246.     call set printLine_19=%%printLine_19:~0,%longestLineLength%%%
  247.     echo ^| %printLine_19% ^|
  248.  
  249. @rem LINE 20
  250.     set printLine_20=----------------------------------------------------------------------------------------------------------------------------------------------------
  251.     call set printLine_20=%%printLine_20:~0,%longestLineLength%%%
  252.     echo +-%printLine_20%-+
  253.  
  254. echo:
  255.  
  256. echo [Press any key to close this window]
  257. pause >nul
  258. exit /b
  259.  
  260.  
  261. :toUppercase
  262.     if not defined %~1 exit /b
  263.     for %%a in ("a=A" "b=B" "c=C" "d=D" "e=E" "f=F" "g=G" "h=H" "i=I" "j=J" "k=K" "l=L" "m=M" "n=N" "o=O" "p=P" "q=Q" "r=R" "s=S" "t=T" "u=U" "v=V" "w=W" "x=X" "y=Y" "z=Z" "ä=Ä" "ö=Ö" "ü=Ü") do (
  264.         call set %~1=%%%~1:%%~a%%
  265.     )
  266.     goto :eof
  267.  
  268. :strlen <resultVar> <stringVar>
  269.     (  
  270.         setlocal EnableDelayedExpansion
  271.         (set^ tmp=!%~2!)
  272.         if defined tmp (
  273.             set "len=1"
  274.             for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
  275.                 if "!tmp:~%%P,1!" NEQ "" (
  276.                     set /a "len+=%%P"
  277.                     set "tmp=!tmp:~%%P!"
  278.                 )
  279.             )
  280.         ) ELSE (
  281.             set len=0
  282.         )
  283.     )
  284.     (
  285.         endlocal
  286.         set "%~1=%len%"
  287.         exit /b
  288.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement