Private Sub btnOSDetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOSDetails.Click
rtbDetails.Clear()
Try
Dim myScope As New ManagementScope("\\" & Environment.MachineName & "\root\cimv2")
Dim oQuery As New SelectQuery("SELECT CSDVersion FROM win32_operatingsystem")
Dim oResults As New ManagementObjectSearcher(myScope, oQuery)
Dim oItem As ManagementObject
Dim oProperty As PropertyData
For Each oItem In oResults.Get()
For Each oProperty In oItem.Properties
Try
rtbDetails.AppendText(oProperty.Name & " : " & oProperty.Value & vbCrLf)
Catch ex As Exception
End Try
Next
Next
Catch ex As Exception
MsgBox("2 : " & ex.Message)
End Try
End Sub
Imports System
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices
'-----------------------------------------------------------------------------------
'Used with WindowsVersionSP()
<StructLayout(LayoutKind.Sequential)> _
Public Structure OSVersionInfo2
Public OSVersionInfoSize As Int32
Public MajorVersion As Int32
Public MinorVersion As Int32
Public BuildNumber As Int32
Public PlatformId As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
Public ServicePack As String
End Structure 'OSVersionInfo2
Public Class OSLibWrap
Declare Ansi Function GetVersionEx2 Lib "kernel32" Alias "GetVersionExA" ( _
ByRef osvi As OSVersionInfo2) As Boolean
End Class 'OSLibWrap
'This part goes in a module
'----------------------------------------------------------------------------------------------
'See this path for more info - I am using the structure version
'C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\Technologies\Interop\PlatformInvoke\WinAPIs\VB\OSinfo.vb
'=====================================================
'=====================================================
'Returns Windows version, service pack and build number using VB.NET and API
'Win95 returns version "4.00"
'WIn98 returns version "4.10"
'WinNT/2000 returns version "5.00"
'WinXP returns version "5.01"
'PlatformID Major Version Minor Version Operating System
'1= Win32Windows >= 4 0 Win95
'1= Win32Windows >= 4 > 0 && < 90 Win98
'1= Win32Windows >= 4 > 0 && >= 90 WinMe
'2= Win32NT <= 4 0 WinNT
'2= Win32NT 5 5 0 Win2K
'2= Win32NT 5 5 > 0 WinXP
Public Function WindowsVersionSP(ByRef sOSver As String, ByRef lOSid As Int32, ByRef lSpack As Int32, ByRef lBuild As Int32) As String
'Console.WriteLine(ControlChars.CrLf + "Passing OSVersionInfo as struct")
Dim sServPack As String
Dim osvi2 As New OSVersionInfo2
osvi2.OSVersionInfoSize = Marshal.SizeOf(osvi2) 'Determine size of structure
OSLibWrap.GetVersionEx2(osvi2)
sOSver = CStr(osvi2.MajorVersion) & "." & CStr(osvi2.MinorVersion)
lBuild = osvi2.BuildNumber
lOSid = osvi2.PlatformId
'If osvi2.PlatformId = 1 then Win95/98/ME
'If osvi2.PlatformId = 2 then WinNT 3.51/WinNT 4.0/WinXP
'If OS Ver is > 5.00 then it is XP and I change lOSid to 3 later on in the code
'Get service pack info
sServPack = osvi2.ServicePack
'If WinNT/2000 there should be a Service Pack value 1-7 if a SP is installed
'If No service pack is installed in Win NT 4.0 or Win2000 then this value will be
'all nulls. In Win95/98 the first char will always be a space
'Return the first char in sServPack string
If sServPack.Substring(0, 1) = "S" Then 'This would mean WinNT/2000 if true
sServPack = Replace(sServPack, Chr(0), "") 'Trim nulls
'Return rightmost/last char should be 1 to 7
sServPack = sServPack.Substring(sServPack.Length - 1, 1)
Else
sServPack = "0" 'No service pack available May be Win95/98
End If
lSpack = CInt(sServPack) 'This will be service pack number 1-7 or 0 for NO sp
If CSng(sOSver) > 5.0 Then lOSid = 3 'This means WinXP
Return (sOSver) 'This is redundant but I may use it later
End Function