Announcement

Collapse
No announcement yet.

Need a way to detect whether the current OS is windows server or windows 10

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

  • Need a way to detect whether the current OS is windows server or windows 10

    Hi All

    I need my PB program to detect whether it is running on a Windows server or Windows 10 OS.
    Appreciate any suggestion on this. Thank you
    There must be some kinda signature to check whether the current system is Windows server or Windows 10 OS ?
    or Windows 7 or 8 ?


  • #2
    I've been using this for quite some time. There's probably a more elegant way to do it today and I'm sure that someone smarter than me will jump in. But this should work.
    Code:
    #COMPILE EXE
    
    #INCLUDE "win32api.inc"  ' Provides OSVERSIONINFOEXW struct
    
    '-- Windows versions values returned by GetWindowsVersion (not win32api values).
    %WIN_VER_WIN95        = 1
    %WIN_VER_WIN98        = 2
    %WIN_VER_WINME        = 3
    %WIN_VER_WINNT3       = 4
    %WIN_VER_WINNT4       = 5
    %WIN_VER_WIN2000      = 6
    %WIN_VER_WINXP        = 7
    %WIN_VER_WINSVR2003   = 8
    %WIN_VER_WINSVR2003R2 = 9
    %WIN_VER_WINHOMESVR   = 10
    %WIN_VER_WINVISTA     = 11
    %WIN_VER_WINSVR2008   = 12
    %WIN_VER_WIN7         = 13
    %WIN_VER_WINSVR2008R2 = 14
    %WIN_VER_WIN8         = 15
    %WIN_VER_WINSVR2012   = 16
    %WIN_VER_WIN81        = 17
    %WIN_VER_WINSVR2012R2 = 18
    %WIN_VER_WIN10        = 19  ' Added 2017-03-09
    %WIN_VER_WINSVR2016   = 20  ' Added 2017-03-09
    
    '-- RtlGetVersion declaration doesn't seem to be in latest PB include files.
    DECLARE FUNCTION RtlGetVersion LIB "NtDll.dll" ALIAS "RtlGetVersion" _
        (OsVerInfoEx AS OSVERSIONINFOEXW) AS LONG ' Returns %STATUS_SUCCESS (0) on success.
    
    FUNCTION GetWindowsVersion() AS LONG ' Returns a version ID from above constants or 0 if fail
      LOCAL osvi AS OSVERSIONINFOEXW     ' Struct to hold actual OS information (from win32api.inc)
    
      osvi.dwOsVersionInfoSize = SIZEOF(osvi)
      IF RtlGetVersion(osvi) THEN EXIT FUNCTION ' Rtn value was not zero so exit now
    
      '-- Look for match of OS major and minor versions. Is a bit trickier after WinXP.
      SELECT CASE osvi.dwMajorVersion
        CASE 3 AND osvi.dwMinorVersion = 51 : FUNCTION = %WIN_VER_WINNT3
        CASE 4 AND osvi.dwMinorVersion = 0  : FUNCTION = %WIN_VER_WINNT4
        CASE 5 AND osvi.dwMinorVersion = 0  : FUNCTION = %WIN_VER_WIN2000
        CASE 5 AND osvi.dwMinorVersion = 1  : FUNCTION = %WIN_VER_WINXP
        CASE 5 AND osvi.dwMinorVersion = 2
          IF GetSystemMetrics(%SM_SERVERR2) = 0 THEN
            FUNCTION = %WIN_VER_WINSVR2003
          ELSEIF GetSystemMetrics(%SM_SERVERR2) <> 0 THEN
            FUNCTION = %WIN_VER_WINSVR2003R2
          ELSEIF osvi.wSuiteMask AND %VER_SUITE_WH_SERVER THEN
            FUNCTION = %WIN_VER_WINHOMESVR
          END IF
        CASE 6 AND osvi.dwMinorVersion = 0
          IF osvi.wProductType = %VER_NT_WORKSTATION THEN
            FUNCTION = %WIN_VER_WINVISTA
          ELSE
            FUNCTION = %WIN_VER_WINSVR2008
          END IF
        CASE 6 AND osvi.dwMinorVersion = 1
          IF osvi.wProductType = %VER_NT_WORKSTATION THEN
            FUNCTION = %WIN_VER_WIN7
          ELSE
            FUNCTION = %WIN_VER_WINSVR2008R2
          END IF
        CASE 6 AND osvi.dwMinorVersion = 2
          IF osvi.wProductType = %VER_NT_WORKSTATION THEN
            FUNCTION = %WIN_VER_WIN8
          ELSE
            FUNCTION = %WIN_VER_WINSVR2012
          END IF
        CASE 6 AND osvi.dwMinorVersion = 3
          IF osvi.wProductType = %VER_NT_WORKSTATION THEN
            FUNCTION = %WIN_VER_WIN81
          ELSE
            FUNCTION = %WIN_VER_WINSVR2012R2
          END IF
        CASE 10 AND osvi.dwMinorVersion = 0
          IF osvi.wProductType = %VER_NT_WORKSTATION THEN
            FUNCTION = %WIN_VER_WIN10
          ELSE
            FUNCTION = %WIN_VER_WINSVR2016
          END IF
      END SELECT
    END FUNCTION ' GetWindowsVersion
    
    
    FUNCTION PBMAIN () AS LONG
      PRINT "Windows Version =" GetWindowsVersion
      WAITKEY$
    END FUNCTION

    Comment


    • #3
      Thank you Sir Wilson
      That's a very good program

      Comment

      Working...
      X