Results 1 to 6 of 6

Thread: Service Pack info

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Post

    Anyone know how to get the current service pack number from an NT oS?
    I can get os, version and build, but not sp!

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Sure. If you use GetVersionEx API. You would have to pass OSVERSIONINFO structure. So, the element szCSDVersion of that structure is holding that information i.e. string like "Service Pack 3")

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819



    [This message has been edited by Serge (edited 11-22-1999).]

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Post

    I tried a couple variations of your suggestion and got errors or no information. I must be implementing it wrong. This is what I did:
    In a module I put:
    Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByVal lpVersionInformation As OSVERSIONINFO) As Long
    Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128 ' Maintenance string for PSS usage
    End Type
    Public myosversion As OSVERSIONINFO

    in my form code I put:
    GetVersionEx myosversion
    Text1.Text = Text1.Text & "buildno" & myosversion.dwBuildNumber

    With this code i get errors "user defined type may not be passed byVal"

    VB help suggested removing 'byval' from the declaration. When I did that, all elements of the 'type' returned '0' except szCSDVersion which returned a null string.

    What am I doing wrong?

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Even though I sent you the correct code, I'll post it here anyway, so other people can use it.

    Copy this to a module:

    Code:
    Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
    Public Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128 ' Maintenance string for PSS usage
    End Type
    Public g_udtOS As OSVERSIONINFO

    Use this on any event you want:

    Code:
    Dim lRet As Long
        
        g_udtOS.dwOSVersionInfoSize = Len(g_udtOS)
        lRet = GetVersionEx(g_udtOS)
        If lRet Then
            Text1.Text = g_udtOS.dwBuildNumber
        Else
             MsgBox "Error retrieving OS version."
        End If

    Note: szCSDVersion element will show you Service Pack Number only in WindowsNT. For Windows95/98 it will return arbitrary additional information about the operating system.


    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  5. #5
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Post

    I have not been at this very long so I am most likely wrong since serge is a lot more experienced then I am but;
    how about this
    Text1.Text = g_udtOS.dwBuildNumber
    changing to this
    Text1.Text = g_udtOS.szCSDVersion
    to get the service pack info.
    thank you for your time and have a good day

    ------------------
    I am so skeptacle, I can hardly believe it!

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Post

    Badgers -
    Thanks, but the code I posted was just a small sample. I did in fact have the line you suggested, but the problem I encountered was unrelated to which information I was showing.
    See the reply from Serge above - he hit the nail on the head - it was a problem with the way the GetVersionEx function was described in the API viewer. Thanks anyway!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width