• Comparing OSVersionInfoEx to System Information “version”

    Home » Forums » AskWoody support » Windows » Windows – other » Comparing OSVersionInfoEx to System Information “version”

    Author
    Topic
    #507074

    I’m trying to build a function that returns the OS version to an application. Does anyone know how to correlate the OSVersionInfoEx information to what a user would see on their System Information display? These show the current major.minor.build for Windows 10 Home as:

    OSVersionInfoEx: 6.2.9200
    System Information: 10.0.14393

    Thanks for any input!

    Viewing 2 reply threads
    Author
    Replies
    • #1579403

      If you don’t get any feedback here, maybe the Windows Programming forum might be a better place to post.

      Lugh.
      ~
      Alienware Aurora R6; Win10 Home x64 1803; Office 365 x32
      i7-7700; GeForce GTX 1060; 16GB DDR4 2400; 1TB SSD, 256GB SSD, 4TB HD

    • #1579406

      On my Insider build 14931 both System Information program and WinVer show the same thing.

      --Joe

    • #1579409

      I’m trying to build a function that returns the OS version to an application. Does anyone know how to correlate the OSVersionInfoEx information to what a user would see on their System Information display?

      You haven’t mentioned what you want to use the function in but is this article about using the Windows API in C# any use?

      Alternatively, for .NET there’s this article (which is very similar).

      Or PowerShell:

      Code:
      if ($OSVersionInfo -eq $null) {
        Set-Variable OSVersionInfo -Value (&{
          begin {
            $bf = {param([Int32]$i) [Reflection.BindingFlags]$i}
            
            $SuiteMask = {param([Int32]$i)
              (-join (($ht = @{
                VER_SUITE_BACKOFFICE               = 0x0004
                VER_SUITE_BLADE                    = 0x0400
                VER_SUITE_COMPUTE_SERVER           = 0x4000
                VER_SUITE_DATACENTER               = 0x0080
                VER_SUITE_ENTERPRISE               = 0x0002
                VER_SUITE_EMBEDDEDNT               = 0x0040
                VER_SUITE_PERSONAL                 = 0x0200
                VER_SUITE_SINGLEUSERTS             = 0x0100
                VER_SUITE_SMALLBUSINESS            = 0x0001
                VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x0020
                VER_SUITE_STORAGE_SERVER           = 0x2000
                VER_SUITE_TERMINAL                 = 0x0010
                VER_SUITE_WH_SERVER                = 0x8000
              }).Keys | % {
                if (($i -band $ht[$_]) -eq $ht[$_]) {$_ + “`n”}
              })).Trim()
            }
            
            $ProductType = {param([Int32]$i)
              @(‘VER_NT_WORKSTATION’,’VER_NT_DOMAIN_CONTROLLER’, ‘Unknown’, ‘VER_NT_SERVER’)[(–$i)]
            }
            
            $ver = New-Object Object
          }
          process {
            $OSVERSIONINFOEX = ($Win32Native = [Object].Assembly.GetType(
              ‘Microsoft.Win32.Win32Native’
            )).GetNestedType(
              ‘OSVERSIONINFOEX’, (&$bf 32)
            ).InvokeMember(
              $null, (&$bf 512), $null, $null, $null
            )
            
            if (!$Win32Native.GetMethod(
              ‘GetVersionEx’, (&$bf 40), $null, [Type[]]@($OSVERSIONINFOEX.GetType()), $null
            ).Invoke(
              $null, @($OSVERSIONINFOEX)
            )) {
              (New-Object ComponentModel.Win32Exception(
                [Runtime.InteropServices.Marshal]::GetLastWin32Error()
              )).Message
              return
            }
            
            $OSVERSIONINFOEX.GetType().GetFields((&$bf 36)) | % {
              if ($_.Name -notmatch ‘(?:(OSVersion)|(Reserved))’) {
                $ver | Add-Member $_.Name -MemberType NoteProperty -Value $(
                  $val = $_.GetValue($OSVERSIONINFOEX)
                  switch ($_.Name) {
                    ‘SuiteMask’   {&$SuiteMask $val}
                    ‘ProductType’ {&$ProductType $val}
                    default       {$val}
                  }
                ) #value
              } #if
            } #foreach
          }
          end {
            $ver
          }
        }) -Option Constant -Scope Global
      }

      If I just need something quick-and-dirty I use WMI (from within AutoHotkey, but you could use VBS) which produces:

      45670-os_ver

      from this:

      Code:
      strComputer := “.”
      objWMIService := ComObjGet(“winmgmts:{impersonationLevel=impersonate}!\” . strComputer . “rootcimv2”)
      colSettings := objWMIService.ExecQuery(“Select * from Win32_OperatingSystem”)._NewEnum
      While colSettings[objOSItem]
      {
      MsgBox % “Version: ” . objOSItem.Version
      }

      Or, alternatively:

      Code:
      RegRead, ProductName, HKLMSOFTWAREMicrosoftWindows NTCurrentVersion, ProductName
      RegRead, ReleaseID, HKLMSOFTWAREMicrosoftWindows NTCurrentVersion, ReleaseID
      RegRead, CurrentBuildNumber, HKLMSOFTWAREMicrosoftWindows NTCurrentVersion, CurrentBuildNumber
      MsgBox, 64, The operating system is…, %ProductName% (Version/Build: %ReleaseID%.%CurrentBuildNumber%)

      whick gives this:

      45671-os_ver1

      Hope this helps…

    Viewing 2 reply threads
    Reply To: Comparing OSVersionInfoEx to System Information “version”

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: