Visual Basic Foro
Programación => Visual Basic 6 => Mensaje iniciado por: pedroesca en Septiembre 12, 2011, 08:06:35 am
-
Señores desarrolladores: quisiera saber si alguien aquí sabe como averiguar (por código obviamente), la versión de Windows (si es XP, Vista, Seven, 3.1, 95, 2000, Millenium, Server, Surface, Phone jaja) y también si la arquitectura es de 32 o 64 bits.
Es para registrar las librerías (DLL, OCX, etc.) de forma silenciosa y automática.
Desde ya muchas gracias. Saludos a todos.
-
Option Explicit
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Type OSVERSIONINFO
OSVSize As Long
dwVerMajor As Long
dwVerMinor As Long
dwBuildNumber As Long
PlatformID As Long
szCSDVersion As String * 128
End Type
Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2
' Returns the version of Windows that the user is running
Public Function GetWindowsVersion() As String
Dim osv As OSVERSIONINFO
osv.OSVSize = Len(osv)
If GetVersionEx(osv) = 1 Then
Select Case osv.PlatformID
Case VER_PLATFORM_WIN32s
GetWindowsVersion = "Win32s on Windows 3.1"
Case VER_PLATFORM_WIN32_NT
GetWindowsVersion = "Windows NT"
Select Case osv.dwVerMajor
Case 3
GetWindowsVersion = "Windows NT 3.5"
Case 4
GetWindowsVersion = "Windows NT 4.0"
Case 5
Select Case osv.dwVerMinor
Case 0
GetWindowsVersion = "Windows 2000"
Case 1
GetWindowsVersion = "Windows XP"
Case 2
GetWindowsVersion = "Windows Server 2003"
End Select
Case 6
Select Case osv.dwVerMinor
Case 0
GetWindowsVersion = "Windows Vista/Server 2008"
Case 1
GetWindowsVersion = "Windows 7/Server 2008 R2"
End Select
End Select
Case VER_PLATFORM_WIN32_WINDOWS:
Select Case osv.dwVerMinor
Case 0
GetWindowsVersion = "Windows 95"
Case 90
GetWindowsVersion = "Windows Me"
Case Else
GetWindowsVersion = "Windows 98"
End Select
End Select
Else
GetWindowsVersion = "Unable to identify your version of Windows."
End If
End Function
Private Sub Form_Load()
MsgBox GetWindowsVersion
End Sub
Fuente: http://stackoverflow.com/questions/4839210/how-can-i-determine-the-windows-version-from-a-vb-6-app (http://stackoverflow.com/questions/4839210/how-can-i-determine-the-windows-version-from-a-vb-6-app)
-
Este es mas exacto, mas corto y mas exacto creo.
Private Function GetOSName() As String
Dim WMI_Obj, WMI_ObjProps, ObjClsItem
Set WMI_Obj = GetObject("winmgmts:\\.\root\cimv2")
Set WMI_ObjProps = WMI_Obj.ExecQuery("Select * from Win32_OperatingSystem", , 48)
For Each ObjClsItem In WMI_ObjProps
GetOSName = ObjClsItem.Caption & " " & ObjClsItem.CSDVersion & " " & ObjClsItem.Version
Exit For
Next
End Function
Private Sub Form_Load()
MsgBox GetOSName
End Sub
-
mejor la forma con api, WMI puede no funcionar segun permisos.
-
Haaa, eso no me lo sabia, gracias por la info Seba
-
IsWow64Process (http://msdn.microsoft.com/en-us/library/ms684139%28v=vs.85%29.aspx) (msdn)
IsWow64Process (http://allapi.mentalis.org/apilist/204681CC993005C53238F78B48EA9F58.html) (Api Guide)
una alternativa seria verificar si existe "sysWOW64" osea si si existe es x64 y si no es x86
private Declare Function FileExists Lib "kernel32" Alias "GetShortPathNameA" (ByVal sFile As String, ByVal nu As Any, ByVal nu As Long) As Long
Dim x64 as boolean
''''''''''''''''''''''''''''''''''''''''''
If (FileExists(Environ("WinDir") & "\sysWOW64", 0&, 0) <> 0) Then
x64 = true
else
x64 = false
end if