CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Detect Windows

  1. #1
    Join Date
    May 2001
    Posts
    17

    Detect Windows

    How can I detect what OS the system is running(I care only for Windows 98, 2000, NT)?
    Thanks



  2. #2
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Detect Windows

    Try to play with this code (create new project and add this code into Form1):


    private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (byref lpVersionInformation as OSVERSIONINFO) as Long

    private 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

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

    private sub Form_Load()
    dim sVer as OSVERSIONINFO ' version structure
    sVer.dwOSVersionInfoSize = len(sVer) ' size of structure

    ' get it
    if (GetVersionEx(sVer) = 0) then
    ' error - do error parsing if needed
    msgbox "error In Retrieving Version Info"
    else
    ' got it - parse the platform ID
    select case (sVer.dwPlatformId)
    case VER_PLATFORM_WIN32_NT:
    ' check for WinNT/2000
    if (sVer.dwMajorVersion <= 4) then
    msgbox "Platform: WinNT"
    elseif (sVer.dwMajorVersion = 5) then
    msgbox "Platform: Win2000"
    else
    msgbox "Platform: Future Platform???"
    end if
    case VER_PLATFORM_WIN32_WINDOWS:
    ' check for win98/95
    if ((sVer.dwMajorVersion > 4) or ((sVer.dwMajorVersion == 4) and (sVer.dwMinorVersion > 0))) then
    msgbox "Platform: Win98"
    else
    msgbox "Platform: Win95"
    end if
    case VER_PLATFORM_WIN32s:
    msgbox "Platform: Win32"
    end select
    end if
    end sub




    Have fun,
    -Cool Bizs

    Good Luck,
    -Cool Bizs

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

Featured