bshipps64_Code_OSV

BuildOSVersionString$

Simple example of compiling a descriptive string of the OS version.

  • Here are a couple functions for putting together an OS version string. I originally started with the GetOSVersionInfo function, then wrote BuildOSVersionString$ to convert the numbers returned by the former into a string like "Windows XP 5.1.2600 Service Pack 2". There's probably an API call to do this exact same thing, but the orignal focus was actually the GetOSVersionInfo() function.
print BuildOSVersionString$()
end
 
function BuildOSVersionString$()
    success = GetOSVersionInfo(major, minor, build, platform, csdv$)
 
    if (success) then
        win$        = "Windows "
        platfrm$    = str$(platform)
        major$      = str$(major) + "."
        minor$      = str$(minor) + "."
        build$      = str$(build) + " "
 
        if (major = 6) then
            os$ = "Vista or Server " + chr$(34) + "Longhorn" + chr$(34)
        else
            select case (minor)
                case (0)
                    if (major = 5) then os$ = "2000"
                    if (major = 4) then os$ = word$("95 NT", platform)
 
                case (1)
                    os$ = "XP"
 
                case (2)
                    os$ = "Server 2003, Server 2003 R2, or XP Professional x64 Edition"
 
                case (10)
                    os$ = "98"
 
                case (90)
                    os$ = "Me"
            end select
        end if
 
        os$ = os$ + " "
        BuildOSVersionString$ = win$ + os$ + major$ + minor$ + build$ + csdv$
    end if
end function
 
 
function GetOSVersionInfo(byref majV, byref minV, byref build, byref plat, byref csdV$)
    struct OSVERSIONINFOA,_
        dwOSVersionInfoSize as ulong,_
        dwMajorVersion      as ulong,_
        dwMinorVersion      as ulong,_
        dwBuildNumber       as ulong,_
        dwPlatformID        as ulong,_
        szCSDVersion        as char[128]
 
    OSVERSIONINFOA.dwOSVersionInfoSize.struct = len(OSVERSIONINFOA.struct)
 
    calldll #kernel32, "GetVersionExA",_
        OSVERSIONINFOA      as struct,_
        GetOSVersionInfo    as boolean
 
    if (GetOSVersionInfo) then
        majV    = OSVERSIONINFOA.dwMajorVersion.struct
        minV    = OSVERSIONINFOA.dwMinorVersion.struct
        build   = OSVERSIONINFOA.dwBuildNumber.struct
        plat    = OSVERSIONINFOA.dwPlatformID.struct
        csdV$   = OSVERSIONINFOA.szCSDVersion.struct
    end if
end function