I included detection for 95/98/ME even though its highly unlikely that those OS' will be running the Framework and also that 95 doesnt support it.
Just wanted to say Thanks to those that helped with getting the final touches working:
VBDT
Negative0
bmahler
There is still a little more work to be done for 2003 but I figure I will post what I have done for now and update it later just so others can start
using it and report any issues that may arise.
I had to trim out the trusts, dll imports and enums to fit but its all included in the zip attachment.
Code attachment written on 2003 SP1
Code:Option Explicit On Option Strict On 'VB.NET FAQ Written by RobDog888 (vbforums.com) Imports System.Runtime.InteropServices Public Class Form1 Inherits System.Windows.Forms.Form "Windows Form Designer generated code" "STRUCTS AND ENUMS" "DLLS AND CONSTS" Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click Me.Close() End Sub Private Sub btnDetectOS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDetectOS.Click txtDetectOS.Text = GetOSPlatVerType() End Sub Private Function GetOSPlatVerType() As String 'Windows Server "Longhorn" 6.0 'Windows Vista 6.0 'Windows Server 2003 R2 5.2 'Windows Server 2003 5.2 'Windows XP Professional x64 Edition 5.2 'Windows XP Pro 5.1 'Windows XP Home 5.1 'Windows Server 2000 5.0 'Windows 2000 Pro 5.0 'Windows ME 4.90 'Windows 98 4.10 'Windows 95 4.0 'Windows NT4 4.0 Dim osvi As OSVERSIONINFO = New OSVERSIONINFO Dim xosvi As OSVERSIONINFOEX = New OSVERSIONINFOEX Dim iRet As Int32 = 0 Dim strDetails As String = String.Empty osvi.dwOSVersionInfoSize = Marshal.SizeOf(GetType(OSVERSIONINFO)) xosvi.dwOSVersionInfoSize = Marshal.SizeOf(GetType(OSVERSIONINFOEX)) Try iRet = System.Environment.OSVersion.Platform If iRet = 1 Then iRet = GetVersionAdv(osvi) strDetails = Environment.NewLine & "Version: " & _ osvi.dwMajorVersion & "." & osvi.dwMinorVersion & "." & osvi.dwBuildNumber & _ Environment.NewLine & osvi.szCSDVersion Select Case Len(osvi) Case 0 Return "Windows 95" & strDetails Case 10 Return "Windows 98" & strDetails Case 9 Return "Windows ME" & strDetails End Select Else '2 (NT) iRet = GetVersionEx(xosvi) strDetails = Environment.NewLine & "Version: " & _ xosvi.dwMajorVersion & "." & xosvi.dwMinorVersion & "." & xosvi.dwBuildNumber & Environment.NewLine & _ xosvi.szCSDVersion & " (" & xosvi.wServicePackMajor & "." & xosvi.wServicePackMinor & ")" Select Case xosvi.dwMajorVersion Case OSMajorVersion.VER_OS_NT4 Return "Windows NT 4" & strDetails Case OSMajorVersion.VER_OS_2K_XP_2K3 Select Case xosvi.dwMinorVersion Case 0 '2000 Select Case xosvi.wProductType Case WinPlatform.VER_NT_WORKSTATION Return "Windows 2000 Pro" & strDetails Case WinPlatform.VER_NT_SERVER If (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_DATACENTER) = WinSuiteMask.VER_SUITE_DATACENTER Then Return "Windows 2000 Datacenter Server" & strDetails ElseIf (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_ENTERPRISE) = WinSuiteMask.VER_SUITE_ENTERPRISE Then Return "Windows 2000 Advanced Server" & strDetails ElseIf (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_SMALLBUSINESS) = WinSuiteMask.VER_SUITE_SMALLBUSINESS Then Return "Windows 2000 Small Business Server" & strDetails Else Return "Windows 2000 Server" & strDetails End If Case WinPlatform.VER_NT_DOMAIN_CONTROLLER If (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_DATACENTER) = WinSuiteMask.VER_SUITE_DATACENTER Then Return "Windows 2000 Datacenter Server Domain Controller" & strDetails ElseIf (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_ENTERPRISE) = WinSuiteMask.VER_SUITE_ENTERPRISE Then Return "Windows 2000 Advanced Server Domain Controller" & strDetails ElseIf (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_SMALLBUSINESS) = WinSuiteMask.VER_SUITE_SMALLBUSINESS Then Return "Windows 2000 Small Business Server Domain Controller" & strDetails Else Return "Windows 2000 Server Domain Controller" & strDetails End If End Select Case 1 'XP If (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_PERSONAL) = WinSuiteMask.VER_SUITE_PERSONAL Then Return "Windows XP Home Edition" & strDetails Else Return "Windows XP Professional Edition" & strDetails End If Case 2 '2003/Vista Select Case xosvi.wProductType Case WinPlatform.VER_NT_WORKSTATION Return "Windows XP Professional x64 Edition" & strDetails Case WinPlatform.VER_NT_SERVER If GetSystemMetrics(SM_SERVERR2) = 1 Then Return "Windows Server 2003 R2" & strDetails Else Return "Windows Server 2003" & strDetails End If Case WinPlatform.VER_NT_DOMAIN_CONTROLLER If GetSystemMetrics(SM_SERVERR2) = 1 Then Return "Windows Server 2003 R2 Domain Controller" & strDetails Else Return "Windows Server 2003 Domain Controller" & strDetails End If End Select End Select Case OSMajorVersion.VER_OS_VISTA_LONGHORN If xosvi.wProductType = WinPlatform.VER_NT_WORKSTATION Then If (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_PERSONAL) = WinSuiteMask.VER_SUITE_PERSONAL Then Return "Windows Vista (Home Premium, Home Basic, or Home Ultimate) Edition" Else Return "Windows Vista (Enterprize or Business)" & strDetails End If Else Return "Windows Server (Longhorn)" & strDetails End If End Select End If Catch MessageBox.Show(GetLastError.ToString) Return String.Empty End Try End Function End Class






Reply With Quote