Results 1 to 10 of 10

Thread: Using registry to determine Window's OS name, any downside?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Location
    Mn-USA
    Posts
    124

    Using registry to determine Window's OS name, any downside?

    I just verified manually that I can determine which Windows OS I'm on from the registry:

    HKEY_LOCAL_MACHINE\software\microsoft\windows nt\
    currentversion
    ProductName

    I manually verified on W7, W8, W10 that they are valid.

    This seems too easy. What's wrong here?
    Last edited by VB-only; Apr 25th, 2021 at 05:44 PM.
    There is a computer disease that anybody who works with computers knows about. It's a very serious disease and it interferes completely with the work. The trouble with computers is that you 'play' with them!
    Richard P. Feynman

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,439

    Re: Using registry to determine Window's OS name, any downside?

    Quote Originally Posted by VB-only View Post
    I just verified manually that I can determine which Windows OS I'm on from the registry:

    HKEY_LOCAL_MACHINE\software\microsoft\windows nt\
    currentversion
    ProductName

    I manually verified on W7, W8, W10 that they are valid.

    This seems too easy. What's wrong here?
    Nothing wrong there.
    Might take a look at this: https://stackoverflow.com/questions/...-from-registry
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Location
    Mn-USA
    Posts
    124

    Re: Using registry to determine Window's OS name, any downside?

    Thank you for that link. But now I'm even more confused. My app will be run on different versions oof Windows around the world. I only need to know whether the user is running W10 or not W10 in order to specify Help information.

    According to that link, Currentversion may not give the correct data.

    So maybe just check for CurrentMajorVersionNumber, and if I get a 10 back, then that would satisfy me.
    There is a computer disease that anybody who works with computers knows about. It's a very serious disease and it interferes completely with the work. The trouble with computers is that you 'play' with them!
    Richard P. Feynman

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,152

    Re: Using registry to determine Window's OS name, any downside?

    Try this

    Code:
    Option Explicit
    
    Private Declare Function RtlGetVersion Lib "ntdll" (lpVersionInformation As Any) As Long
    
    Private Sub Form_Load()
        If RealOsVersion = 1000 Then
            MsgBox "Yes!", vbExclamation
        End If
    End Sub
    
    Property Get RealOsVersion() As Long
        Static lVersion As Long
        Dim aBuffer() As Long
        
        If lVersion = 0 Then
            ReDim aBuffer(0 To 100) As Long
            aBuffer(0) = UBound(aBuffer) * 4
            RtlGetVersion aBuffer(0)
            lVersion = aBuffer(1) * 100 + aBuffer(2)
        End If
        RealOsVersion = lVersion
    End Property
    cheers,
    </wqw>

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Using registry to determine Window's OS name, any downside?

    The whole point of version-lie appcompat shims is to keep old programs working. If your program really is properly written to run on Windows 10 then your manifest should declare this. Once you've done that all documented ways of retrieving version info work fine.

    Instead of fixing your problem you are applying crude bandaging.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Location
    Mn-USA
    Posts
    124

    Re: Using registry to determine Window's OS name, any downside?

    Thank you for that elegant solution. However, I don't understand what it's doing and seems to be way too overkill for my needs. If it were to break sometime in the future, I wouldn't know how to fix it.

    I'm always in need of simple solutions to complex problems. But thanks just the same.
    There is a computer disease that anybody who works with computers knows about. It's a very serious disease and it interferes completely with the work. The trouble with computers is that you 'play' with them!
    Richard P. Feynman

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Using registry to determine Window's OS name, any downside?

    There are two potential pitfalls in the hack of reading that registry value.

    Microsoft might move it somewhere else later on (unlikely). Microsoft may start providing spoofed values as part of the version-lie shim (more likely but still not very likely).

    But hey, you could always do the job correctly.

  8. #8
    Lively Member Grant Swinger's Avatar
    Join Date
    Jul 2015
    Posts
    71

    Re: Using registry to determine Window's OS name, any downside?

    Have you tried using WMI? You can get the Windows version from Win32_OperatingSystem class in the root/CIMV2 namespace. It's easy to do. Here's an example in VBScript.

    Code:
    strComputer = "." 
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
    Set colItems = objWMIService.ExecQuery( _
        "SELECT * FROM Win32_OperatingSystem",,48) 
    For Each objItem in colItems 
        Wscript.Echo "-----------------------------------"
        Wscript.Echo "Win32_OperatingSystem instance"
        Wscript.Echo "-----------------------------------"
        Wscript.Echo "Version: " & objItem.Version
    Next
    It will return a value like this: 10.0.19042. This is Windows 10. XP will 5, Vista 6.0, Win7 6.1, and Win8 6.2.

  9. #9
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    EspaƱa
    Posts
    508

    Re: Using registry to determine Window's OS name, any downside?

    In case it helps you.
    https://github.com/M2000Interpreter/.../clsOSInfo.cls
    I use this class

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Using registry to determine Window's OS name, any downside?

    WMI is an admin scripting tool. It isn't meant for use within applications and access to it may well be disabled via Group Policy for most users.

Posting Permissions

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



Click Here to Expand Forum to Full Width