Solved

How to detect Windows XP SP2 installed using VB6?

Posted on 2004-10-09
4
1,400 Views
Last Modified: 2008-02-26
How does my VB6 application detect if the application is running on a machine that has Windows XP SP2 installed?
0
Comment
Question by:samuel999
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Shahid Thaika
ID: 12269441
I don't have SP2 installed on my system. But if SP2 is installed on any system, a value will be entered in the registry. You just have to check for this value. If it is true, then SP2 is installed.

Service Pack 1 entry is saved in...
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion (BuildLab) or (CSDVersion)

If you have SP2 installed, you can try searching for the value 'Service Pack 2' or SP2 in your registry

Hope this answer helps you :)
0
 
LVL 9

Expert Comment

by:Shahid Thaika
ID: 12269452
Oh incase you don't know how to read a value from the registry, here is a nice tutorial...
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=1881
0
 

Expert Comment

by:jrolson
ID: 12271833
This code might help you.
It will find the version of Windows.

Module Code
Public Type OSVERSIONINFOEX
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2

Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFOEX) As Long

Form Code
Public Function OSVersion() As String
   
    Dim udtOSVersion As OSVERSIONINFOEX
    Dim lMajorVersion  As Long
    Dim lMinorVersion As Long
    Dim lPlatformID As Long
    Dim sAns As String
   
   
    udtOSVersion.dwOSVersionInfoSize = Len(udtOSVersion)
    GetVersionEx udtOSVersion
    lMajorVersion = udtOSVersion.dwMajorVersion
    lMinorVersion = udtOSVersion.dwMinorVersion
    lPlatformID = udtOSVersion.dwPlatformId
   
    Select Case lMajorVersion
        Case 5
            sAns = "Windows 2000"
        Case 4
            If lPlatformID = VER_PLATFORM_WIN32_NT Then
                sAns = "Windows NT 4.0"
            Else
                sAns = IIf(lMinorVersion = 0, _
                "Windows 95", "Windows 98")
            End If
        Case 3
            If lPlatformID = VER_PLATFORM_WIN32_NT Then
                sAns = "Windows NT 3.x"
            Else
                sAns = "Windows 3.x"
            End If
           
        Case Else
            sAns = "Unknown Windows Version"
    End Select
                   
    OSVersion = sAns
   
End Function

Private Sub Form_Load()
     MsgBox "Windows version detected: " & OSVersion
End Sub
0
 
LVL 4

Accepted Solution

by:
AjithJose earned 50 total points
ID: 12272021
In the above code in type OSVERSIONINFOEX structure, szCSDVersion will contain the Service Pack installed

Try following code in a module

Public Type OSVERSIONINFOEX
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2

Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFOEX) As Long

Form Code
Public Function GetInstalledServicePack() As String
   
    Dim udtOSVersion As OSVERSIONINFOEX
    Dim lPlatformID As Long
   
   
    udtOSVersion.dwOSVersionInfoSize = Len(udtOSVersion)
    GetVersionEx udtOSVersion

    lPlatformID = udtOSVersion.dwPlatformId

    If lPatrformID  =VER_PLATFORM_WIN32_NT then
           GetInstalledServicePack=udtOSVersion.szCSDVersion
    end if

End Function
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now