Windows build number check

Discussion in 'Scripting' started by jim_p, Dec 7, 2023.

  1. jim_p

    jim_p MDL Senior Member

    Dec 11, 2013
    460
    173
    10
    Can systeminfo (of command prompt > systeminfo) provide me with the major build number of w10? I want to check if something is in 19045.x.
     
  2. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,484
    1,486
    60
    execute winver
     
  3. jim_p

    jim_p MDL Senior Member

    Dec 11, 2013
    460
    173
    10
    I know about winver, but I am looking for something whose output can be echoed* in a text file.
    If the above is not doable, is there a database or page or something that lists ALL version of windows 10/10 with their build number? E.g. 22h2 is 19045.x, 21h2 is 19044.x and so on.

    *"Echoed" is not the right word probably, but I am talking about the equivalent of the (function?) ">" executes, but in windows
    Code:
    dmesg | grep aword > afile.txt
    The above runs dmesg (built in shell command), searches the entire output for "aword" and outputs all the lines containing it to "afile.txt".
     
  4. GezoeSloog

    GezoeSloog knows a guy, who knows another guy.

    Feb 10, 2012
    877
    8,557
    30
  5. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,484
    1,486
    60
    Try these powershell commands :
    Code:
    $Version = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
    "Microsoft Windows version $($Version.DisplayVersion) (Operating system build $($Version.CurrentBuildNumber).$($Version.UBR))" `
    |Out-File "path to your file"
    File content example :
    Microsoft Windows version 23H2 (Operating system build 22631.2792)
     
  6. jim_p

    jim_p MDL Senior Member

    Dec 11, 2013
    460
    173
    10
    I think that what GezoeSloog suggested above is the simplest way one can do it. Not that the long powershell is bad, it is just that an average user will run it and writing all that is impossible.
    A few months ago she was asked to write "choco install something --reinstall" in powershell and I had to guide her step by step.

    Also, thank you for mentioning "get-itemproperty". I assume it is the similar to the source command in linux, e.g.
    Code:
    $ echo $VERSION_CODENAME
    (returns nothing)
    $ source /etc/os-release
    $ echo $VERSION_CODENAME
    trixie
     
  7. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,484
    1,486
    60
    I agree, the long powershell statement is ugly and unpractical, but it can be split.
    The execution of a cmd script with the following statements :
    Code:
    @set "s=$V=gp 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion';"
    @set "s=%s%\"Microsoft $($V.ProductName) version"
    @set "s=%s% $($V.DisplayVersion) (Operating system build"
    @set "s=%s% $($V.CurrentBuildNumber).$($V.UBR))\""
    @powershell %s%&pause
    displays (on my pc) :
    Microsoft Windows 10 Enterprise version 23H2 (Operating system build 22631.2861)
     
  8. EXO56

    EXO56 MDL Member

    Mar 22, 2013
    199
    292
    10
    CMD batch to export Window version from registry to a text file:
    (Build number, Edition and Codename)

    Code:
    @echo off
    cmd /c ver > c:\Version.txt
    reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "ProductName" >> c:\Version.txt
    reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "DisplayVersion" >> c:\Version.txt
    Query will be output to a text file named "Version.txt" in C:\
    Modify both according to your needs.

    Output example:
    Code:
    Microsoft Windows [Version 10.0.19045.3693]
    
    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion
        ProductName    REG_SZ    Windows 10 Pro
    
    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion
        DisplayVersion    REG_SZ    22h2
     
  9. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,484
    1,486
    60
    Code:
    @echo off
    set "key=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    for /F "skip=2 tokens=1,2*" %%I in ('reg query "%key%" /v ProductName') do set "PN=%%K"
    for /F "skip=2 tokens=1,2*" %%I in ('reg query "%key%" /v DisplayVersion') do set "DV=%%K"
    for /F "skip=2 tokens=1,2*" %%I in ('reg query "%key%" /v CurrentBuildNumber') do set "CBN=%%K"
    for /F "skip=2 tokens=1,2*" %%I in ('reg query "%key%" /v UBR') do set /A "UBR=%%K"
    echo Microsoft %PN% version %DV% (Operating system build %CBN%.%UBR%)
    pause
     
  10. EXO56

    EXO56 MDL Member

    Mar 22, 2013
    199
    292
    10
    #10 EXO56, Dec 14, 2023
    Last edited: Dec 15, 2023
    Parts of my batch were taken from my script in WinPE (PECMD)

    [​IMG]
     
  11. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,484
    1,486
    60
    For Windows 10 & 11 :
    Code:
    @echo off
    set "key=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    for /f "tokens=6 delims=[]. " %%I in ('ver') do set build=%%I
    IF %build% GEQ 19041 SET "Win=10"
    IF %build% GEQ 21996 SET "Win=11"
    for /F "skip=2 tokens=1,2*" %%I in ('reg query "%key%" /v EditionID') do set "Edition=%%K"
    for /F "skip=2 tokens=1,2*" %%I in ('reg query "%key%" /v DisplayVersion') do set "DV=%%K"
    for /f "tokens=4 delims=] " %%i in ('ver') do set "build=%%i"
    echo Microsoft Windows %Win% %Edition% version %DV% (Operating system build %build%)
    pause
     
  12. MarvelX7

    MarvelX7 MDL Member

    Jun 1, 2021
    234
    230
    10
    Works Good
    SS.png
     
  13. adric

    adric MDL Expert

    Jul 30, 2009
    1,406
    1,544
    60
    #13 adric, Dec 14, 2023
    Last edited: Dec 14, 2023
    FYI: "displayversion" value is nonexistant for older Win 10 versions such as LTSB 1607 and LTSC 1809 before 2xHx started being used by Msoft.
    Code:
    ERROR: The system was unable to find the specified registry key or value.
    Microsoft Windows  EnterpriseS version  (Operating system build 10.0.17763.5206)
    
     
  14. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,484
    1,486
    60
    #14 rpo, Dec 15, 2023
    Last edited: Dec 16, 2023
    Y're right. The script is ok starting with build 19041.

    You could try this (not sure if your powershell version returns needed infos) :
    Code:
    @echo off
    set "s=$ubr=(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').ubr;"
    set "s=%s%$info=Get-ComputerInfo;"
    set "s=%s%\"$($info.OSName) "
    set "s=%s%version $($info.OSDisplayVersion) "
    set "s=%s%(Operating system build $($Info.OsVersion).$ubr)\""
    powershell "$progressPreference='silentlyContinue';%s%"
    pause
     
  15. Amiga2025

    Amiga2025 MDL Novice

    Jan 17, 2025
    5
    0
    0
    was actually looking for a way to add the value from HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').DisplayVersion to the desktop along with version and build that is enabled by the "HKCU\Control Panel\Desktop" /V PaintDesktopVersion tweak.
     
  16. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,484
    1,486
    60
    Have a look here : How to show Windows 10 version on desktop
     
  17. Amiga2025

    Amiga2025 MDL Novice

    Jan 17, 2025
    5
    0
    0
    Seriously. Your link IS the paintdesktop tweak. Everyone knows about the paintdesktop tweak.

    The problem is that the tweak does not enable display of HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').DisplayVersion (ie 22H2, 23H2,24H2 etc)
    It only show Os Version (Windows 11) and Build #.
     
  18. Carlos Detweiller

    Carlos Detweiller Emperor of Ice-Cream

    Dec 21, 2012
    6,811
    7,787
    210
    Neither the PaintDesktopVersion (HKCU\ControlPanelDesktop) nor DisplayVersion (HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows) keys can display that value. They are hardcoded and only show the true base build number.
    DisplayVersion (HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion) is only in Registry and can be easily faked, possibly that's why they didn't include it. Either that or they actually never updated that ancient feature at all, like a lot of old things in Windows.

    You might be able to use a tool like DesktopInfo.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. EXO56

    EXO56 MDL Member

    Mar 22, 2013
    199
    292
    10
    This is not possible with a simple registry tweak.
    The trick is mostly seen in WinPE's as in live OS it's involving patched critical Windows system initialization files.

    [​IMG]

    Since you only need to show the "DisplayVersion" (22H2/23H2/24H2), easy workaround is to modify the "BuildLab" key value to whatever you like:

    [​IMG]
     
  20. Amiga2025

    Amiga2025 MDL Novice

    Jan 17, 2025
    5
    0
    0
    i considered modifying the registry to insert the display version data, but worry it might affect something that actually needs that data to not be modified, perhaps Update Target version. Might as well modify ProductName. ;)
    But modifying ProductName doesn't work.