Resumen ¿Cómo saber la versión de Windows?   (2 mensajes )

Alberto Perdomo wrote:

> ¿Como determino el sistema operativo (win95 o winNT) mediante una
> función API?

En Win 95 tenes que usar la funcion GetVersionEx

Declare Function GetVersionEx Lib "Kernel32" Alias "GetVersionExA" _
    (lpVersionInformation As OSVERSIONINFO) As Long

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

Para definir OSVERSIONINFO:

Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
end type

Y por ultimo:
Dim lpVersionInfo As OSVERSIONINFO

lpVersionInfo.dwOSVersionInfoSize = 148
GetVersionEx lpVersionInfo

Si el OS es W95:
lpVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS

Si es NT:
lpVersionInfo.dwPlatformId= VER_PLATFORM_WIN32_NT

Espero te sirva
Saludos
Olavo

--
        C. Olavo Vieira
         Maldonado 2076
     Montevideo - Uruguay
           CP 11200
     Cel: +598 99 662 199

Solo te puedo responder a una parte y la respuesta va en inglés :( porque es un artículo de la Knowledge Base de Microsoft que explica cómo saber sobre qué versión de Windows se está ejecutando la aplicación.

Espero que te sirva:

---------------------------
Determine Which 32-Bit Windows Version Is Being Used


---------------------------------------------------------------------
The information in this article applies to:

 - Microsoft Visual Basic Learning, Professional, and Enterprise Editions
   for Windows, version 5.0
 - Microsoft Visual Basic Standard and Professional Editions, 32-bit only,
   for Windows, version 4.0
 - Microsoft Visual Basic for Applications, version 5.0
---------------------------------------------------------------------

SUMMARY
=======

An application may need to perform tasks differently depending on which
operating system is running on the computer. This article shows, by
example, how to differentiate between Windows 95, Windows 98, Window NT
3.51, and Windows NT 4.0.

The Win32 GetVersionEx function returns information that a program can use
to identify the operating system. Among those values are the major and
minor revision numbers and a platform identifier. With the introduction of
Windows 98, it now takes a more involved logical evaluation to determine
which version of Windows is in use. The listing below provides the data
needed to evaluate the OSVERSIONINFO structure populated by GetVersionEx:

                   Win95 Win98 WinNT 3.51 WinNT 4.0
                  ------------------------------------------------

dwPlatFormID 1 1 2 2

dwMajorVersion 4 4 3 4

dwMinorVersion 0 10 51 0

MORE INFORMATION
================

Step-by-Step Example
--------------------

1. Start a new Standard EXE project in Visual Basic. Form1 is created by
   default.

2. From the Project menu, add a Standard Module to the project.

3. Insert the following code into Module1:

      Public Declare Function GetVersionExA Lib "kernel32" _
         (lpVersionInformation As OSVERSIONINFO) As Integer

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

      Public Function getVersion() As String
         Dim osinfo As OSVERSIONINFO
         Dim retvalue As Integer

         osinfo.dwOSVersionInfoSize = 148
         osinfo.szCSDVersion = Space$(128)
         retvalue = GetVersionExA(osinfo)

         With osinfo
         Select Case .dwPlatformId
            Case 1
               If .dwMinorVersion = 0 Then
                  getVersion = "Windows 95"
               ElseIf .dwMinorVersion = 10 Then
                  getVersion = "Windows 98"
               End If
            Case 2
               If .dwMajorVersion = 3 Then
                  getVersion = "Windows NT 3.51"
               Elseif .dwMajorVersion = 4 Then
                  getVersion = "Windows NT 4.0"
               End If
            Case Else
               getVersion = "Failed"
         End Select
         End With
      End Function

4. Add the following line of code to the Load event of Form1:

      MsgBox GetVersion()

5. Run the project, and note that a message box displays the correct
   Windows version.

REFERENCES
==========

For more information, please see the following article in the Microsoft
Knowledge Base:

   ARTICLE-ID: Q92936
   TITLE : HOWTO: Get Windows 3.1 Version Number in VB with GetVersion



Resumen Resumen

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com