Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

Code-Beispiel

Code-Beispiele » System

Windows-Version ermitteln

Lizenz:Erster Autor:Letzte Bearbeitung:
k. A.Redakteurytwinky 13.01.2015

Der folgende Code ermittelt die Windows-Version, auf der das Programm ausgeführt wird. Erkannt werden alle Windows-Versionen von Windows NT 3.51 über Windows 9x bis hin zu Windows 10.

#Include Once "windows.bi"

Function GetOSplatform () As Integer
  Dim OSV As OSVERSIONINFO
  Dim OSVEx As OSVERSIONINFOEX
  Dim mOsVersion As String
  Dim Erg As Integer

  OSV.dwOSVersionInfoSize = SizeOf(OSV)'Laenge des UDT angeben
  Erg = GetVersionEx(@OSV)             'Funktion aufrufen und
  If Erg <> 0 Then                     'Rueckgabewert abfragen

    Select Case OSV.dwPlatformId
      Case 0
        mOsVersion = " ??"
      Case 1
        Select Case OSV.dwMinorVersion
          Case 0
            mOsVersion = "95"
          Case 10
            mOsVersion = " 98"
            If (OSV.dwBuildNumber And &HFFFF) = 2222 Then
              mOsVersion = " 98 SE"
            End If
          Case 90
            mOsVersion = " ME"
        End Select
      Case 2
        OSVEx.dwOsVersionInfoSize = SizeOf(OSVEx)
        Erg = GetVersionEx (Cast(LPOSVERSIONINFO,@OSVEx))

        Select Case OSVEx.dwMajorVersion
          Case 3
            mOsVersion = " NT 3.51"
          Case 4
            mOsVersion = " NT 4.0"
          Case 5
            Select Case OSVEx.dwMinorVersion
              Case 0
                mOsVersion = "2000"
              Case 1
                mOsVersion = " XP"
              Case 2
                mOsVersion = " Server 2003"
            End Select
          Case 6
            Select Case OSVEx.dwMinorVersion
              Case 0
                If OSVEx.wProductType = VER_NT_WORKSTATION Then
                  mOsVersion = " Vista"
                Else
                  mOsVersion = " Server 2008"
                EndIf
              Case 1
                If OSVEx.wProductType = VER_NT_WORKSTATION Then
                  mOsVersion = "7"
                Else
                  mOsVersion = " Server 2008 R2"
                EndIf
              Case 2
                If OSVEx.wProductType = VER_NT_WORKSTATION Then
                  mOsVersion = "8"
                Else
                  mOsVersion = " Server 2012"
                EndIf
              Case 3
                If OSVEx.wProductType = VER_NT_WORKSTATION Then
                  mOsVersion = "8.1"
                Else
                  mOsVersion = " Server 2012 R2"
                EndIf
              Case 4
                If OSVEx.wProductType = VER_NT_WORKSTATION Then
                  mOsVersion = "10"
                Else
                  mOsVersion = " unknown"
                EndIf
            End Select

            Dim GetProductInfo As Function (  _
            dwOSMajorVersion As UInteger, _
            dwOSMinorVersion As UInteger, _
            dwSpMajorVersion As UInteger, _
            dwSpMinorVersion As UInteger, _
            pdwReturnedProductType As UInteger Ptr) As Integer
            Dim dwType As UInteger
            Dim As Any Ptr kernel32
            kernel32 = DylibLoad("kernel32")

            If kernel32 Then
              GetProductInfo = DyLibSymbol(kernel32, "GetProductInfo")
              If GetProductInfo Then
                GetProductInfo( OSVEx.dwMajorVersion, OSVEx.dwMinorVersion, 0, 0, @dwType)
                Select Case dwType
                  Case 1'PRODUCT_ULTIMATE
                    mOsVersion += " Ultimate"
                  Case 2'PRODUCT_HOME_BASIC
                    mOsVersion += " Home Basic"
                  Case 3'PRODUCT_HOME_PREMIUM
                    mOsVersion += " Home Premium"
                  Case 4'PRODUCT_ENTERPRISE
                    mOsVersion += " Enterprise"
                  Case 6'PRODUCT_BUSINESS
                    mOsVersion += " Business"
                  Case 11'PRODUCT_STARTER
                    mOsVersion += " Starter"
                  Case &H30'PRODUCT_PROFESSIONAL
                    mOsVersion += " Professional"
                  Case &H67'PRODUCT_PROFESSIONAL_WMC
                    mOsVersion += " Professional Media Center"
                  Case &HABCDABCD'PRODUCT_UNLICENSED
                    mOsVersion += " Unlicensed product"
                End Select
              EndIf
            EndIf
        End Select
    End Select

    MessageBox (0, "Windows" + mOsVersion + Chr(10) _
    + Trim(Str(OSV.dwMajorVersion)) + ". " _
    + Trim(Str(OSV.dwMinorVersion)) + ". " _
    + Trim(Str(OSV.dwBuildNumber And &HFFFF)) + " " _
    + Trim(OSV.szCSDVersion), "Windows - Version", MB_OK)

  End If
  GetOSplatform = OSV.dwPlatformId
End Function

GetOSplatform


Zusätzliche Informationen und Funktionen
  • Das Code-Beispiel wurde am 07.11.2007 von Redakteurytwinky angelegt.
  • Die aktuellste Version wurde am 13.01.2015 von RedakteurVolta gespeichert.
  Bearbeiten Bearbeiten  

  Versionen Versionen