Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

OpSys Info Wrapper Win 3.1 up through Vista

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • OpSys Info Wrapper Win 3.1 up through Vista

    Often I see examples that ask the Operating System Info to see if a DLL may exist, but usually it is just to see if NT or not. So I took it a step farther and did a lil wrapper to give me as much of the basics of what OS you are running. All the way back from Windows 3.1, to WinNT, to Vista.

    So hopefully I did not miss any.

    "OpSysInfo.h"
    Code:
    'Windows < Win95
    '--------------------------------------------------------------------------------
    '
    '               Win 3.1
    'PlatformID     0
    'Major Version
    'Minor Version
    'Build
    '
    '--------------------------------------------------------------------------------
    'Windows 95/98/ME
    '--------------------------------------------------------------------------------
    '               Win     Win     Win
    '               95      98      Me
    '               ---     ---     ---
    'PlatformID     1       1       1
    'Major Version  4       4       4
    'Minor Version  0       10      90
    'Build          950*    1111    1998
    '
    '--------------------------------------------------------------------------------
    'Old Windows NT
    '--------------------------------------------------------------------------------
    '
    '               Win     Win     Win     Win
    '               NT      NT      NT      2000
    '               3.0     3.1     4
    '               ---     ---     ---     ----
    'PlatformID     2       2       2       2
    'Major Version  3       3       4       5
    'Minor Version  0       1       0       0
    'Build                          1381    2195
    '
    '--------------------------------------------------------------------------------
    'Windows NT
    '--------------------------------------------------------------------------------
    '
    '               Win     Win     Win
    '               2003    XP      VISTA
    'PlatformID     2       2       2
    'Major Version  5       5       6
    'Minor Version  2       1       0
    'Build          3790    2600    TBD
    '
    '--------------------------------------------------------------------------------
    
    DECLARE SUB GetOsInfo()
    DECLARE FUNCTION GetWindowsOs() AS STRING
    DECLARE FUNCTION GetWindowsBuildNumber() AS STRING
    DECLARE FUNCTION GetWindowsBuildName() AS STRING
    DECLARE FUNCTION GetWindowsServicePack() AS STRING
    GLOBAL OsInfo AS OSVERSIONINFO
    "OpSysInfo.INC"
    Code:
    '**************************************************************************************************************
    '*** OS Info Wrapper by Cliff Nichols 11-28-07
    '*** Complete list of Functions and OS values can be seen in OpSysInfo.h
    '**************************************************************************************************************
    
    SUB GetOsInfo()
    '     OsInfo.dwOSVersionInfoSize = 148                      'Unsure why 148 works but %MAX_PATH comes back as 0
         OsInfo.dwOSVersionInfoSize = SIZEOF(OsInfo)            'Now know this should be SIZEOF(OsInfo)
    '    OsInfo.szCsdVersion = SPACE$(128)
         OsInfo.szCsdVersion = SPACE$(SIZEOF(OsInfo))           'Now know this should be SIZEOF(OsInfo)
         GetVersionEx(OsInfo)                                   'Get the information
    END SUB
    
    FUNCTION GetWindowsOs() AS STRING
         SELECT CASE OsInfo.dwPlatformId                        'If Platform not known
              CASE 0
                   GetOsInfo                                    'Get the Info
         END SELECT
         SELECT CASE OsInfo.dwPlatformId
              CASE 0                                            'Platform is < Win95
                   FUNCTION = "Windows 3.1"
              CASE 1                                            'Platform is Win 95/98/ME
                   SELECT CASE OsInfo.dwMajorVersion
                        CASE 4                                  'Win 95/98/ME
                             SELECT CASE OsInfo.dwMinorVersion
                                  CASE 0                        'Win 95
                                       FUNCTION = "Windows 95"
                                  CASE 10                       'Win 98
                                       FUNCTION = "Windows 98"
                                  CASE 90                       'Win ME
                                       FUNCTION = "Windows ME"
                             END SELECT
                   END SELECT
              CASE 2                                            'Platform is Win NT 3/4/5/6
                   SELECT CASE OsInfo.dwMajorVersion
                        CASE 3                                  'Win NT 3
                             SELECT CASE OsInfo.dwMinorVersion
                                  CASE 0                        'Win NT 3
                                       FUNCTION = "Windows NT 3.0"
                                  CASE 1                        'Win NT 3.1
                                       FUNCTION = "Windows NT 3.1"
                             END SELECT
                        CASE 4                                  'Win NT 4
                             SELECT CASE OsInfo.dwMinorVersion
                                  CASE 0                        'Win NT 4
                                       FUNCTION = "Windows NT 4.0"
                             END SELECT
                        CASE 5                                  'Win NT 5
                             SELECT CASE OsInfo.dwMinorVersion
                                  CASE 0                        'Win 2000
                                       FUNCTION = "Windows 2000"
                                  CASE 1                        'Win XP
                                       FUNCTION = "Windows XP"
                                  CASE 2                        'Windows 2003 Server"
                                       FUNCTION = "Windows 2003 Server"
                             END SELECT
                        CASE 6                                  'Win NT 6
                             SELECT CASE OsInfo.dwMinorVersion
                                  CASE 0                        'Win Vista
                                       FUNCTION = "Windows Vista"
                             END SELECT
                   END SELECT
         END SELECT
    END FUNCTION
    
    FUNCTION GetWindowsBuildNumber() AS STRING
         SELECT CASE OsInfo.dwBuildNumber                       'If Build Number not known
              CASE 0
                   GetOsInfo                                    'Get the Build Number
         END SELECT
         FUNCTION = STR$(OsInfo.dwBuildNumber)
    END FUNCTION
    
    FUNCTION GetWindowsBuildName() AS STRING
         SELECT CASE OsInfo.dwBuildNumber                       'If Build Number not known
              CASE 0
                   GetOsInfo                                    'Get the Build Number
         END SELECT
         SELECT CASE OsInfo.dwBuildNumber
              CASE 950                                          'Win 95
                   FUNCTION = ""
              CASE 1111                                         'Win 98 OSR2
                   FUNCTION = STR$(OsInfo.dwBuildNumber) + " OSR2"
              CASE 1998                                         'Win ME
                   FUNCTION = ""
              CASE 1381                                         'Win NT 4
                   FUNCTION = ""
              CASE 2195                                         'Win 2000
                   FUNCTION = ""
              CASE 3790                                         'Win 2003 Server
                   FUNCTION = ""
              CASE 2600                                         'Win XP
                   FUNCTION = ""
         END SELECT
    END FUNCTION
    
    FUNCTION GetWindowsServicePack() AS STRING
         SELECT CASE OsInfo.szCSDVersion                        'If Service Pack unknownd
              CASE ""
                   GetOsInfo                                    'Get Service Pack
         END SELECT
         FUNCTION = OsInfo.szCSDVersion
    END FUNCTION
    And a Test App
    "OsInfo.exe"
    Code:
    #COMPILE EXE
    #DIM ALL
    
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #INCLUDE "WIN32API.INC"       'Windows API
    #INCLUDE "OpSysInfo.h"        'OpSysInfo Declares
    #INCLUDE "OpSysInfo.INC"      'OpSysInfo Functions
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    %IDD_DIALOG1 =  %WM_USER + 1
    %IDC_LABEL1  = %WM_USER + 2
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION PBMAIN()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' Initialization handler
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CBCTL
                    CASE %IDC_LABEL1
                END SELECT
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
         LOCAL OsInfo AS STRING
    
        LOCAL lRslt AS LONG
        LOCAL hDlg  AS DWORD
        DIALOG NEW hParent, "Dialog1", %CW_USEDEFAULT, %CW_USEDEFAULT, 200, 40, %WS_POPUP OR _
            %WS_BORDER OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_SYSMENU OR _
            %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
            %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
            OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "Label1", 5, 0, 190, 40
    '*** Show Windows Information
         IF GetWindowsOs <> "" THEN OsInfo = "Operating System: " + GetWindowsOs + $CR
         IF GetWindowsBuildNumber <> "" THEN OsInfo = OsInfo + "Build: " + GetWindowsBuildNumber + $CR
         IF GetWindowsBuildName <> "" THEN OsInfo = OsInfo + "Build Name: " + GetWindowsBuildName + $CR
         IF GetWindowsServicePack <> "" THEN OsInfo = OsInfo + "Service Pack: " + GetWindowsServicePack + $CR
         CONTROL SET TEXT hDlg, %IDC_LABEL1, OsInfo
    '***
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "
Working...
X