Tipp 0373 Installiertes Service-Pack ermitteln (Registry)
Autor/Einsender:
Datum:
  Markus Schutz
14.02.2005 (Update)
Entwicklungsumgebung:   VB 5
Dieser Tipp zeigt wie man aus der Registry das installierte Service-Pack der Betriebssysteme NT, 2000 und XP ermitteln kann.
Hinweis
In diesem Beispiel wurde auch der Code aus Tipp Aktuelles Betriebssystem ermitteln verwendet und ist daher hier nicht noch mal gesondert abgebildet.
Code im Codebereich des Moduls modGetServicePackREG
 
Option Explicit

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
      "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As _
      String, ByVal uloptions As Long, ByVal samDesired As Long, _
      phkResult As Long) As Long

Private Declare Function RegCloseKey Lib "advapi32.dll" _
      (ByVal hKey As Long) As Long

Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
      Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal _
      lpValueName As String, ByVal lpReserved As Long, lpType _
      As Long, lpData As Any, lpcbData As Any) As Long

Public Const HKEY_LOCAL_MACHINE = &H80000002

Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10

Private Const KEY_READ = KEY_QUERY_VALUE Or _
         KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY

Private Const ERROR_SUCCESS = 0&

Private Const REG_SZ = 1
Private Const REG_DWORD = 4

Public Function GetValue(ByVal root As Long, _
      ByVal key As String, ByVal field As String, _
      ByRef value As Variant) As Boolean

  Dim lResult As Long, hKey As Long, dwType As Long
  Dim zw As Long, nBufferSize As Long, strBuffer As String

  lResult = RegOpenKeyEx(root, key, 0, KEY_READ, hKey)
  GetValue = (lResult = ERROR_SUCCESS)
  If lResult <> ERROR_SUCCESS Then Exit Function

  lResult = RegQueryValueEx( _
          hKey, field, 0&, dwType, ByVal 0&, nBufferSize)
  GetValue = (lResult = ERROR_SUCCESS)
  If lResult <> ERROR_SUCCESS Then Exit Function

  Select Case dwType
    Case REG_SZ
      strBuffer = Space$(nBufferSize + 1)
      lResult = RegQueryValueEx(hKey, field, 0&, dwType, _
              ByVal strBuffer, nBufferSize)
      GetValue = (lResult = ERROR_SUCCESS)
      If lResult <> ERROR_SUCCESS Then Exit Function
      value = strBuffer

    Case REG_DWORD
      nBufferSize = 4
      lResult = RegQueryValueEx(hKey, field, 0&, dwType, _
              zw, nBufferSize)
      GetValue = (lResult = ERROR_SUCCESS)
      If lResult <> ERROR_SUCCESS Then Exit Function
      value = zw
    Case Else
  End Select
  If lResult = ERROR_SUCCESS Then RegCloseKey hKey

  GetValue = True
End Function
 
Beispiel-Aufruf
 
Option Explicit

Public Sub Demo_GetServicePack()

  Const REG_PATH As String = _
        "SOFTWARE\Microsoft\Windows NT\CurrentVersion"

  Dim strPlatForm   As String
  Dim strCSDVersion As String

  strPlatForm = GetWinPlatform

  If strPlatForm = "Windows NT" Or strPlatForm = _
        "Windows 2000" Or strPlatForm = "Windows XP" Then

    GetValue HKEY_LOCAL_MACHINE, REG_PATH, "CSDVersion", _
          strCSDVersion

    MsgBox strPlatForm & vbCrLf & strCSDVersion

  Else
    MsgBox "Das Betriebssystem " & strPlatForm & _
            " wird nicht unterstützt!"
  End If
End Sub
 
Weitere Links zum Thema
Installiertes Service-Pack ermitteln (WMI)
Hinweis für VBA-Anwender
Die zwei im Download befindlichen *.bas-Dateien können für die Verwendung in einem (Office-)Programm im VB-Editor des entsprechenden Programms importiert werden. Ein Import der im Download enthaltenen *.frm-Datei ist nicht möglich.

Windows-Version
95
98/SE
ME
NT
2000
XP
Vista
Win 7
VB-Version
VBA 5
VBA 6
VB 4/16
VB 4/32
VB 5
VB 6


Download  (5,8 kB) Downloads bisher: [ 1036 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Projekte | Tutorials | API-Referenz | VB-/VBA-Tipps | Komponenten | Bücherecke | VB/VBA-Forum | VB.Net-Forum | DirectX-Forum | Foren-Archiv | DirectX | VB.Net-Tipps | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Montag, 15. August 2011