Get detailed Windows version

Share your advanced PureBasic knowledge/code with the community.
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Get detailed Windows version

Post by breeze4me »

Not fully tested.
Not support Win9x.

References:
http://msdn2.microsoft.com/en-us/librar ... S.85).aspx
http://msdn2.microsoft.com/en-us/librar ... S.85).aspx
http://msdn2.microsoft.com/en-us/librar ... S.85).aspx

Code: Select all

#PROCESSOR_ARCHITECTURE_INTEL = 0
;#PROCESSOR_ARCHITECTURE_MIPS             1
;#PROCESSOR_ARCHITECTURE_ALPHA            2
;#PROCESSOR_ARCHITECTURE_PPC              3
;#PROCESSOR_ARCHITECTURE_SHX              4
;#PROCESSOR_ARCHITECTURE_ARM              5
#PROCESSOR_ARCHITECTURE_IA64 = 6
;#PROCESSOR_ARCHITECTURE_ALPHA64          7
;#PROCESSOR_ARCHITECTURE_MSIL             8
#PROCESSOR_ARCHITECTURE_AMD64 = 9
;#PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 = 10

#VER_PLATFORM_WIN32s = 0
#VER_PLATFORM_WIN32_WINDOWS = 1
#VER_PLATFORM_WIN32_NT = 2
#VER_SERVER_NT = $80000000
#VER_WORKSTATION_NT = $40000000
#VER_NT_WORKSTATION = $00000001
#VER_NT_DOMAIN_CONTROLLER = $00000002
#VER_NT_SERVER = $00000003
#VER_SUITE_SMALLBUSINESS = $00000001
#VER_SUITE_ENTERPRISE = $00000002
#VER_SUITE_BACKOFFICE = $00000004
#VER_SUITE_COMMUNICATIONS = $00000008
#VER_SUITE_TERMINAL = $00000010
#VER_SUITE_SMALLBUSINESS_RESTRICTED = $00000020
#VER_SUITE_EMBEDDEDNT = $00000040
#VER_SUITE_DATACENTER = $00000080
#VER_SUITE_SINGLEUSERTS = $00000100
#VER_SUITE_PERSONAL = $00000200
#VER_SUITE_BLADE = $00000400

#PRODUCT_BUSINESS = $00000006 ;Business Edition
#PRODUCT_BUSINESS_N = $00000010 ;Business Edition
#PRODUCT_CLUSTER_SERVER = $00000012 ;Cluster Server Edition
#PRODUCT_DATACENTER_SERVER = $00000008 ;Server Datacenter Edition (full installation)
#PRODUCT_DATACENTER_SERVER_CORE = $0000000C ;Server Datacenter Edition (core installation)
#PRODUCT_ENTERPRISE = $00000004 ;Enterprise Edition
#PRODUCT_ENTERPRISE_N = $0000001B ;Enterprise Edition
#PRODUCT_ENTERPRISE_SERVER = $0000000A ;Server Enterprise Edition (full installation)
#PRODUCT_ENTERPRISE_SERVER_CORE = $0000000E ;Server Enterprise Edition (core installation)
#PRODUCT_ENTERPRISE_SERVER_IA64 = $0000000F ;Server Enterprise Edition For Itanium-based Systems
#PRODUCT_HOME_BASIC = $00000002 ;Home Basic Edition
#PRODUCT_HOME_BASIC_N = $00000005 ;Home Basic Edition
#PRODUCT_HOME_PREMIUM = $00000003 ;Home Premium Edition
#PRODUCT_HOME_PREMIUM_N = $0000001A ;Home Premium Edition
#PRODUCT_HOME_SERVER = $00000013 ;Home Server Edition
#PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = $0000001E ;Windows Essential Business Server Management Server 
#PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = $00000020 ;Windows Essential Business Server Messaging Server 
#PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = $0000001F ;Windows Essential Business Server Security Server 
#PRODUCT_SERVER_FOR_SMALLBUSINESS = $00000018 ;Server For Small Business Edition
#PRODUCT_SMALLBUSINESS_SERVER = $00000009 ;Small Business Server
#PRODUCT_SMALLBUSINESS_SERVER_PREMIUM = $00000019 ;Small Business Server Premium Edition
#PRODUCT_STANDARD_SERVER = $00000007 ;Server Standard Edition (full installation)
#PRODUCT_STANDARD_SERVER_CORE = $0000000D ;Server Standard Edition (core installation)
#PRODUCT_STARTER = $0000000B ;Starter Edition
#PRODUCT_STORAGE_ENTERPRISE_SERVER = $00000017 ;Storage Server Enterprise Edition
#PRODUCT_STORAGE_EXPRESS_SERVER = $00000014 ;Storage Server Express Edition
#PRODUCT_STORAGE_STANDARD_SERVER = $00000015 ;Storage Server Standard Edition
#PRODUCT_STORAGE_WORKGROUP_SERVER = $00000016 ;Storage Server Workgroup Edition
#PRODUCT_UNDEFINED = $00000000 ;An unknown product
#PRODUCT_ULTIMATE = $00000001 ;Ultimate Edition
#PRODUCT_ULTIMATE_N = $0000001C ;Ultimate Edition
#PRODUCT_WEB_SERVER = $00000011 ;Web Server Edition (full installation)
#PRODUCT_WEB_SERVER_CORE = $0000001D ;Web Server Edition (core installation)

#VER_SUITE_COMPUTE_SERVER = $00004000
#VER_SUITE_STORAGE_SERVER = $00002000
#VER_SUITE_BLADE = $00000400
#VER_SUITE_PERSONAL = $00000200

;EnableExplicit

Prototype.l GetNativeSystemInfo(*lpSystemInfo)
Prototype.l GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion, *pdwReturnedProductType)
Prototype.l IsWow64Process(hProcess, *Wow64Process)
Prototype.l GetVersionEx(*lpVersionInfo)

Procedure IsWow64()
  Protected ln, res, IsWow64Process.IsWow64Process
  ln = OpenLibrary(#PB_Any, "kernel32")
  If ln
    IsWow64Process = GetFunction(ln, "IsWow64Process")
    If IsWow64Process
      IsWow64Process(GetCurrentProcess_(), @res)
;       If IsWow64Process(GetCurrentProcess_(), @res) = 0
;         res = -1  ;error
;       EndIf
    EndIf
    CloseLibrary(ln)
  EndIf
  ProcedureReturn res
EndProcedure

Procedure.s GetOSDisplayString()
  Structure myOSVERSIONINFOEX
    dwOSVersionInfoSize.l
    dwMajorVersion.l
    dwMinorVersion.l
    dwBuildNumber.l
    dwPlatformId.l
    szCSDVersion.b[128]
    wServicePackMajor.w
    wServicePackMinor.w
    wSuiteMask.w
    wProductType.b
    wReserved.b
  EndStructure

  Protected ln, osvi.myOSVERSIONINFOEX, si.SYSTEM_INFO, dwType, tmp$, res$
  Protected GetNativeSystemInfo.GetNativeSystemInfo, GetProductInfo.GetProductInfo, GetVersionEx.GetVersionEx
  
  osvi\dwOSVersionInfoSize = SizeOf(myOSVERSIONINFOEX)
  
  ln = OpenLibrary(#PB_Any, "kernel32.dll")
  If ln
    GetVersionEx = GetFunction(ln, "GetVersionExA")   ;both unicode and ascii mode.
    GetNativeSystemInfo = GetFunction(ln, "GetNativeSystemInfo")
    GetProductInfo = GetFunction(ln, "GetProductInfo")
    ;// CALL GetNativeSystemInfo If supported Or GetSystemInfo otherwise.
    If GetNativeSystemInfo
      GetNativeSystemInfo(si)
    Else
      GetSystemInfo_(si)
    EndIf
    If GetVersionEx(osvi)
      If osvi\dwPlatformId = #VER_PLATFORM_WIN32_NT And osvi\dwMajorVersion > 4
         ;// TEST For the specific product.
        If osvi\dwMajorVersion = 6 And osvi\dwMinorVersion = 0
          If osvi\wProductType = #VER_NT_WORKSTATION
            res$ = "Windows Vista "
          Else
            res$ = "Windows Server 2008 "
          EndIf  
          
          GetProductInfo(6, 0, 0, 0, @dwType)
          
          Select dwType
            Case #PRODUCT_ULTIMATE
              res$ + "Ultimate Edition"
            Case #PRODUCT_HOME_PREMIUM
              res$ + "Home Premium Edition"
            Case #PRODUCT_HOME_BASIC
              res$ + "Home Basic Edition"
            Case #PRODUCT_ENTERPRISE
              res$ + "Enterprise Edition"
            Case #PRODUCT_BUSINESS
              res$ + "Business Edition"
            Case #PRODUCT_STARTER
              res$ + "Starter Edition"
            Case #PRODUCT_CLUSTER_SERVER
              res$ + "Cluster Server Edition"
            Case #PRODUCT_DATACENTER_SERVER
              res$ + "Datacenter Edition"
            Case #PRODUCT_DATACENTER_SERVER_CORE
              res$ + "Datacenter Edition (core installation)"
            Case #PRODUCT_ENTERPRISE_SERVER
              res$ + "Enterprise Edition"
            Case #PRODUCT_ENTERPRISE_SERVER_CORE
              res$ + "Enterprise Edition (core installation)"
            Case #PRODUCT_ENTERPRISE_SERVER_IA64
              res$ + "Enterprise Edition for Itanium-based Systems"
            Case #PRODUCT_SMALLBUSINESS_SERVER
              res$ + "Small Business Server"
            Case #PRODUCT_SMALLBUSINESS_SERVER_PREMIUM
              res$ + "Small Business Server Premium Edition"
            Case #PRODUCT_STANDARD_SERVER
              res$ + "Standard Edition"
            Case #PRODUCT_STANDARD_SERVER_CORE
              res$ + "Standard Edition (core installation)"
            Case #PRODUCT_WEB_SERVER
              res$ + "Web Server Edition"
          EndSelect
  ;         If si\wProcessorArchitecture = #PROCESSOR_ARCHITECTURE_AMD64
  ;            res$ + ", 64-bit"
  ;         ElseIf si\wProcessorArchitecture = #PROCESSOR_ARCHITECTURE_INTEL
  ;            res$ + ", 32-bit"
  ;         EndIf
        EndIf
        
        If osvi\dwMajorVersion = 5 And osvi\dwMinorVersion = 2
          If GetSystemMetrics_(#SM_SERVERR2)
            res$ = "Windows Server 2003 R2, "
          ElseIf osvi\wSuiteMask = #VER_SUITE_STORAGE_SERVER
            res$ = "Windows Storage Server 2003"
          ElseIf osvi\wProductType = #VER_NT_WORKSTATION And si\wProcessorArchitecture = #PROCESSOR_ARCHITECTURE_AMD64
            res$ = "Windows XP Professional x64 Edition"
          Else
            res$ = "Windows Server 2003, "
          EndIf
          
          ;// TEST For the server type.
          If osvi\wProductType <> #VER_NT_WORKSTATION
            If si\wProcessorArchitecture = #PROCESSOR_ARCHITECTURE_IA64
              If osvi\wSuiteMask & #VER_SUITE_DATACENTER
                res$ + "Datacenter Edition for Itanium-based Systems"
              ElseIf osvi\wSuiteMask & #VER_SUITE_ENTERPRISE
                res$ + "Enterprise Edition for Itanium-based Systems"
              EndIf
            ElseIf si\wProcessorArchitecture = #PROCESSOR_ARCHITECTURE_AMD64
              If osvi\wSuiteMask & #VER_SUITE_DATACENTER
                res$ + "Datacenter x64 Edition"
              ElseIf osvi\wSuiteMask & #VER_SUITE_ENTERPRISE
               res$ + "Enterprise x64 Edition"
              Else
               res$ + "Standard x64 Edition"
              EndIf
            Else
              If osvi\wSuiteMask & #VER_SUITE_COMPUTE_SERVER
                res$ + "Compute Cluster Edition"
              ElseIf osvi\wSuiteMask & #VER_SUITE_DATACENTER
                res$ + "Datacenter Edition"
              ElseIf osvi\wSuiteMask & #VER_SUITE_ENTERPRISE
                res$ + "Enterprise Edition"
              ElseIf osvi\wSuiteMask & #VER_SUITE_BLADE
                res$ + "Web Edition"
              Else
                res$ + "Standard Edition"
              EndIf
            EndIf
          EndIf
        EndIf
        
        If osvi\dwMajorVersion = 5 And osvi\dwMinorVersion = 1
          If GetSystemMetrics_(#SM_MEDIACENTER)
            res$ = "Windows XP Media Center Edition"
          ElseIf GetSystemMetrics_(#SM_STARTER)
            res$ = "Windows XP Starter Edition"
;         ElseIf GetSystemMetrics_(#SM_TABLETPC)
;           res$ = "Windows XP Tablet PC Edition"
          Else
            res$ = "Windows XP "
          EndIf
          
          If osvi\wSuiteMask & #VER_SUITE_PERSONAL
             res$ + "Home Edition"
          Else
            res$ + "Professional"
          EndIf
        EndIf
        
        If osvi\dwMajorVersion = 5 And osvi\dwMinorVersion = 0
          res$ + "Windows 2000 "
          
          If osvi\wProductType = #VER_NT_WORKSTATION
             res$ + "Professional"
          Else 
            If osvi\wSuiteMask & #VER_SUITE_DATACENTER
              res$ + "Datacenter Server"
            ElseIf osvi\wSuiteMask & #VER_SUITE_ENTERPRISE
              res$ + "Advanced Server"
            Else
              res$ + "Server"
            EndIf
          EndIf
        EndIf
        
        ;// Include service pack (If any) And build number.
        tmp$ = PeekS(@osvi\szCSDVersion, -1, #PB_Ascii)
        If tmp$
          res$ + " " + tmp$
        EndIf
        res$ + " (build " + Str(osvi\dwBuildNumber) + ")"
        
        If IsWow64()
          res$ + ", 64-bit"
        Else
          res$ + ", 32-bit"
        EndIf
      EndIf
    EndIf
    CloseLibrary(ln)
  EndIf
  ProcedureReturn res$
EndProcedure

If OSVersion() >= #PB_OS_Windows_2000
  Debug GetOSDisplayString()
EndIf
oridan
Enthusiast
Enthusiast
Posts: 128
Joined: Tue Oct 12, 2004 12:14 am
Location: Italy
Contact:

Post by oridan »

Hello breeze4me,
you code returns these errors (I use PB 4.02 and Windows XP Home SP2):

Code: Select all

Constant not found: #SM_SERVERR2
Constant not found: #SM_MEDIACENTER
Constant not found: #SM_STARTER
I have added to you code this and now it work:

Code: Select all

#SM_SERVERR2 = 89
#SM_MEDIACENTER = 87
#SM_STARTER = 88
Regards
:wink:
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Post by breeze4me »

oridan wrote:Hello breeze4me,
you code returns these errors (I use PB 4.02 and Windows XP Home SP2):

Code: Select all

Constant not found: #SM_SERVERR2
Constant not found: #SM_MEDIACENTER
Constant not found: #SM_STARTER
I have added to you code this and now it work:

Code: Select all

#SM_SERVERR2 = 89
#SM_MEDIACENTER = 87
#SM_STARTER = 88
Regards
:wink:
hmmm, strange. I have no errors.(PB v4.10)
Because those constants have been added in PB v4.10, maybe I have no errors about that.
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

Thanks, works fine.

Debug output:
Windows XP Professional Service Pack 2 (build 2600), 32-bit
Win XP Pro SP2, PB 4.10
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Great code
Thats all right for me too
Windows 2000 Professional Service Pack 4 (build 2195), 32-bit
Thanks for shared 8)
ImageThe happiness is a road...
Not a destination
Godai
Enthusiast
Enthusiast
Posts: 171
Joined: Thu Oct 05, 2006 8:13 pm

Post by Godai »

Works fine here:
Windows Vista Home Premium Edition (build 6000), 32-bit
Post Reply