Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Dec 2009
    Location
    Nashville
    Posts
    92
    Thanks
    21
    Thanked 5 Times in 4 Posts

    Comparing OSVersionInfoEx to System Information "version"

    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!

  2. #2
    5 Star Lounger Lugh's Avatar
    Join Date
    Jun 2010
    Location
    Indy
    Posts
    620
    Thanks
    166
    Thanked 77 Times in 68 Posts
    If you don't get any feedback here, maybe the Windows Programming forum might be a better place to post.
    Lugh.
    ~
    Windows 10 Pro x64 1607; Office 2016 (365 Home) x32; Win Defender, MBAM Pro

    ASRock H97 Anniversary; Xeon E3-1231V3 (like i7)
    Gigabyte GeForce GTX 970; 12GB Crucial DDR3 1600
    Logitech MX Master mouse; Roccat Isku kb

  3. #3
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,577
    Thanks
    5
    Thanked 1,057 Times in 926 Posts
    On my Insider build 14931 both System Information program and WinVer show the same thing.
    Joe

  4. #4
    Super Moderator Rick Corbett's Avatar
    Join Date
    Dec 2009
    Location
    South Glos., UK
    Posts
    2,143
    Thanks
    101
    Thanked 579 Times in 464 Posts
    Quote Originally Posted by imjcarls
    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:

    os_ver.png

    from this:

    Code:
    strComputer := "."
    objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
    colSettings := objWMIService.ExecQuery("Select * from Win32_OperatingSystem")._NewEnum
    While colSettings[objOSItem]
    {
    MsgBox % "Version: " . objOSItem.Version
    }
    Or, alternatively:

    Code:
    RegRead, ProductName, HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion, ProductName
    RegRead, ReleaseID, HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion, ReleaseID
    RegRead, CurrentBuildNumber, HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion, CurrentBuildNumber
    MsgBox, 64, The operating system is..., %ProductName% (Version/Build: %ReleaseID%.%CurrentBuildNumber%)
    whick gives this:

    os_ver1.png

    Hope this helps...
    Last edited by Rick Corbett; 2016-09-27 at 15:35. Reason: Added PowerShell code

  5. The Following User Says Thank You to Rick Corbett For This Useful Post:

    imjcarls (2016-09-27)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •