Announcement

Collapse
No announcement yet.

Determining Windows OS version

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Determining Windows OS version

    What command can I put in my powerbasic source code so that the compiled program--in real time while the program is running--can determine the Windows OS version of the system that the program is running on? (e.g., Windows 7, Windows 10).

    My program has some features that will only run properly on Windows 10, so if the user is running on older Windows version, I want my program to detect that and disable some features so that the user cannot attempt to invoke them.

    Thanks

  • #2
    There is GetVersionEx.
    https://docs.microsoft.com/en-us/win...-getversionexa
    Rod
    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

    Comment


    • #3
      Try these codes by Pierre
      https://forum.powerbasic.com/forum/u...294#post758294

      But you need to remove those forum's formatting codes like {color] and [/color] etc

      Comment


      • #4
        Got rid of those pesky formatting codes

        Code:
        ' Detect OS version.bas
        ' https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/758292-how-to-detect-windows-versions?p=758294#post758294
        ' By Pierre
        
        'Can detect Window version from 2000 to Ten
        #DIM ALL
        #INCLUDE "Win32Api.inc"
        
        #IF %PB_REVISION < &H1000
        TYPE OSVERSIONINFOEXW
          dwOSVersionInfoSize
          dwMajorVersion      AS DWORD
          dwMinorVersion      AS DWORD
          dwBuildNumber       AS DWORD
          dwPlatformId        AS DWORD
          szCSDVersion        AS STRING * 128 * 2  'Maintenance string for PSS usage (WSTRINGZ)
          wServicePackMajor   AS WORD
          wServicePackMinor   AS WORD
          wSuiteMask          AS WORD
          wProductType        AS BYTE
          wReserved           AS BYTE
        END TYPE
        #ENDIF
        
        DECLARE FUNCTION RtlGetVersion LIB "NtDll.dll" ALIAS "RtlGetVersion" _
        (OsVerInfoEx AS OSVERSIONINFOEXW)  AS LONG 'Unicode function, returns %STATUS_SUCCESS (0) on success.
        
        
        '==============================
        FUNCTION WinVer() AS SINGLE
         LOCAL OsInfoEx AS OSVERSIONINFOEXW
         '2000 5.0, XP 5.1, 2003 5.2, Vista 6.0 Seven 6.1, Eight.Zero 6.2, Eight.One 6.3, and Ten 10.0.
        
         RtlGetVersion(OsInfoEx) 'Get Windows version, Windows 8 & 10 included, unicode only available
         FUNCTION = OsInfoEx.dwMajorVersion + OsInfoEx.dwMinorVersion / IIF(OsInfoEx.dwMinorVersion > 9, 100, 10)
        
        END FUNCTION
        
        
        
        '==========================
        FUNCTION PBMAIN() AS LONG
        
         MSGBOX "You are using Windows version " + STR$(WinVer()), , "Win Version"
        
        END FUNCTION

        Comment


        • #5
          Originally posted by Anne Wilson View Post
          Try these codes by Pierre
          https://forum.powerbasic.com/forum/u...294#post758294

          But you need to remove those forum's formatting codes like {color] and [/color] etc
          I ran it through my BBSCode stripper for you
          '
          Code:
          #COMPILE EXE '#Win 9.07# 'Window version from 2000 to Ten
          #DIM ALL
          #INCLUDE "Win32Api.inc"
          
          #IF %PB_REVISION < &H1000
          TYPE OSVERSIONINFOEXW
            dwOSVersionInfoSize AS DWORD
            dwMajorVersion      AS DWORD
            dwMinorVersion      AS DWORD
            dwBuildNumber       AS DWORD
            dwPlatformId        AS DWORD
            szCSDVersion        AS STRING * 128 * 2 'Maintenance string for PSS usage (WSTRINGZ)
            wServicePackMajor   AS WORD
            wServicePackMinor   AS WORD
            wSuiteMask          AS WORD
            wProductType        AS BYTE
            wReserved           AS BYTE
          END TYPE
          #ENDIF
          
          DECLARE FUNCTION RtlGetVersion LIB "NtDll.dll" ALIAS "RtlGetVersion" _
          (OsVerInfoEx AS OSVERSIONINFOEXW)  AS LONG 'Unicode function, returns %STATUS_SUCCESS (0) on success.
          '_____________________________________________________________________________
          
          FUNCTION WinVer() AS SINGLE
           LOCAL OsInfoEx AS OSVERSIONINFOEXW
           '2000 5.0, XP 5.1, 2003 5.2, Vista 6.0 Seven 6.1, Eight.Zero 6.2, Eight.One 6.3, and Ten 10.0.
          
           RtlGetVersion(OsInfoEx) 'Get Windows version, Windows 8 & 10 included, unicode only available
           FUNCTION = OsInfoEx.dwMajorVersion + OsInfoEx.dwMinorVersion / IIF(OsInfoEx.dwMinorVersion > 9, 100, 10)
          
          END FUNCTION
          '_____________________________________________________________________________
          
          FUNCTION PBMAIN() AS LONG
          
           MSGBOX STR$(WinVer()), , "WinVer"
          
          END FUNCTION
          '_____________________________________________________________________________
          '
          '

          Comment


          • #6
            Anyone here has a windows 11 ?
            And please test out these codes
            and revert back to us the results

            Comment


            • #7
              Looks good Stuart

              Comment


              • #8
                Originally posted by Stuart McLachlan View Post

                I ran it through my BBSCode stripper for you
                I just tidied up my BBSCode stripper and posted it in the Source Code forum:
                https://forum.powerbasic.com/forum/u...ngs#post812241

                Just copy the "formatted" code, run the application and paste the resultant cleaned code.

                Comment


                • #9
                  Thanks so much Stuart

                  Comment

                  Working...
                  X