(c) 2002 Visual Studio Magazine 
Fawcette Technical Publications

Issue
May 2002 VSM
Section
Desktop Developer
Listing file name
Vs0205DTl1.rtf

Listing 1										VB6
Even the Product Suite Counts
Different marketing packages of the Windows operating system can make a difference to your application-especially if you're accessing theWindows API. You use the suite mask (wSuiteMask) and product type (bProductType) members to identify marketing packages, such as Windows 2000 DataCenter or Windows XP Professional.

If verinfo.bProductType = VER_NT_WORKSTATION Then
	If verinfo.wSuiteMask And VER_SUITE_PERSONAL Then
		WindowsName = WindowsName & "Personal "
	Else
			 WindowsName = WindowsName & "Professional "
	End If
ElseIf verinfo.bProductType = VER_NT_SERVER Then
	If verinfo.wSuiteMask And VER_SUITE_DATACENTER Then
			WindowsName = WindowsName & _
				"DataCenter Server "
	 ElseIf verinfo.wSuiteMask And _
		VER_SUITE_ENTERPRISE Then
				 WindowsName = WindowsName & _
					"Advanced Server "
	 Else
			 WindowsName = WindowsName & "Server "
	 End If
End If

Listing A online									VB6
Version, Version, Who's Got the Version?
Your code could find itself running on any of six major versions of Windows, nine sub-versions, and numerous service packs. Each permutation obsolesces some exposed APIs while adding others. Here's how to find out which is which.
Note that The C language example for using GetVersionEx in the MSDN library as of February 2002 would not actually work (in C or converted to Basic). The code shown here is correct, and does work.

Public Function WindowsName() As String
	Dim verinfo As OSVERSIONINFOEX
	Dim bOsVersionInfoEx As Long
' try OSVERSIONINFOEX first
	verinfo.dwOSVersionInfoSize = Len(verinfo)
	bOsVersionInfoEx = GetVersionEx(verinfo)
	If bOsVersionInfoEx = 0 Then
		verinfo.dwOSVersionInfoSize = OSVERSIONINFOSIZE
		GetVersionEx verinfo ' bOsVersionInfo it is
	End If

	Select Case verinfo.dwPlatformId
	Case VER_PLATFORM_WIN32_NT
	If verinfo.dwMajorVersion < 4 Then
		WindowsName = "Microsoft Windows NT 3"
		ElseIf verinfo.dwMajorVersion = 4 Then
			WindowsName = "Microsoft Windows NT 4"
		ElseIf verinfo.dwMajorVersion = 5 And verinfo.dwMinorVersion = 0 Then
		WindowsName = "Microsoft Windows 2000 "

		ElseIf verinfo.dwMajorVersion = 5 And verinfo.dwMinorVersion = 1 Then
		WindowsName = "Microsoft Windows XP "
	End If
	If bOsVersionInfoEx Then
	If verinfo.bProductType = VER_NT_WORKSTATION Then
		If verinfo.wSuiteMask And VER_SUITE_PERSONAL Then
			WindowsName = WindowsName & "Home Edition "
			Else
			WindowsName = WindowsName & "Professional "
		End If
		ElseIf verinfo.bProductType = VER_NT_SERVER Then
		If verinfo.wSuiteMask And VER_SUITE_DATACENTER Then
			WindowsName = WindowsName & "DataCenter Server "
			ElseIf verinfo.wSuiteMask And VER_SUITE_ENTERPRISE Then
			WindowsName = WindowsName & "Advanced Server "
			Else
		WindowsName	 = WindowsName & "Server "
		End If
		End If
	Else
	
		Select Case UCase$(GetSetting("SYSTEM\CurrentControlSet\Control\ProductOptions", "ProductType", 0))
		Case "WINNT"
			WindowsName = WindowsName & "Professional "
		Case "LANMANNT"
			WindowsName = WindowsName & "Server "
		Case "SERVERNT"
			WindowsName = WindowsName & "Advanced Server "
		End Select
		End If
		If verinfo.dwMajorVersion <= 4 Then
		WindowsName = WindowsName & "version " & verinfo.dwMajorVersion & "." & verinfo.dwMinorVersion & verinfo.szCSDVersion & " (Build " & verinfo.dwBuildNumber And &HFFFF & ")"
	Else
		WindowsName = WindowsName & Trim$(verinfo.szCSDVersion) & " (Build " & (verinfo.dwBuildNumber And &HFFFF) & ")"
		End If
   	WindowsName = WindowsName & ", service pack " & verinfo.wServicePackMajor & "." & verinfo.wServicePackMinor

   Case VER_PLATFORM_WIN32_WINDOWS

   	If verinfo.dwMajorVersion = 4 And verinfo.dwMinorVersion = 0 Then
   	
     	WindowsName = "Microsoft Windows 95 "
     	If Mid$(verinfo.szCSDVersion, 1, 1) = "C" Or Mid$(verinfo.szCSDVersion, 1, 1) = "B" Then
        WindowsName = WindowsName & "OSR2 "
        
     	End If

   	ElseIf verinfo.dwMajorVersion = 4 And verinfo.dwMinorVersion = 10 Then
   	
     	WindowsName = "Microsoft Windows 98 "
     	If Mid$(verinfo.szCSDVersion, 1, 1) = "A" Then
        WindowsName = WindowsName & "SE "
        
     	End If
   	
   	ElseIf verinfo.dwMajorVersion = 4 And verinfo.dwMinorVersion = 90 Then
   	
     	WindowsName = "Microsoft Windows Me "
     	
     	
   	End If

   Case VER_PLATFORM_WIN32s

   	WindowsName = "Microsoft Win32s "
   	

  End Select

End Function


(c) 2002 Visual Studio Magazine 
Fawcette Technical Publications


