[VB.NET] NativeOsVersion

  • 0 Respuestas
  • 2508 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado fudmario

  • *
  • Underc0der
  • Mensajes: 198
  • Actividad:
    0%
  • Reputación 13
  • Skype: fudmario
    • Ver Perfil
    • fudmario - GitHub

[VB.NET] NativeOsVersion

  • en: Enero 12, 2017, 08:00:25 pm
Alternativa a Environment.OsVersion.Version, para aplicaciones que no se han manifestado para Windows 8.1 o Windows 10.
Código: (vbnet) [Seleccionar]
    <DllImport("Ntdll.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
    Friend Shared Function RtlGetVersion(<[In], Out> ByVal osversion As RtlOsVersionInfoExW) As Integer
    End Function

    <StructLayout(LayoutKind.Sequential)>
    Public Class RtlOsVersionInfoExW
        Public dwOSVersionInfoSize As UInt32
        Public dwMajorVersion As UInt32
        Public dwMinorVersion As UInt32
        Public dwBuildNumber As UInt32
        Public dwPlataformId As UInt32
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public szCSDVersion As String
        Public wServicePackMajor As UInt16
        Public wServicePackMinor As UInt16
        Public wSuiteMask As UInt16
        Public bProductType As Byte
        Public bReserved As Byte
    End Class

    Public Function NativeOsVersion() As Version
        Dim osVersionInfo As New RtlOsVersionInfoExW()
        osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(GetType(RtlOsVersionInfoExW))
        Dim status As Integer = RtlGetVersion(osVersionInfo)
        If status <> 0 Then
            ' Throw New Win32Exception(RtlNtStatusToDosError(status))
            Return Environment.OSVersion.Version
        End If

        Return New Version(osVersionInfo.dwMajorVersion,
                           osVersionInfo.dwMinorVersion,
                           osVersionInfo.dwBuildNumber)
    End Function