Reputation: 55
How to determine windows build number using vb.net or c#? I do not want to use win32 API.
Upvotes: 2
Views: 3559
Reputation: 99
corsiKa got me on the right track, but it very much depends on what you need. I wanted the full build number, which changes with every Windows 10 Cumulative Update. (ex. 16299.192)
The WMI method is good, but only gets you 10.0.16299, which is the overall release. I used the WMI Code Creator to poke around, but couldn't find the "192" part in WMI.
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\UBR
Has the 192 part of the build number.
I settled on this code to get 10.0.16299.192:
Function GetOSVersion() As String
Dim strBuild1, strBuild2, strBuild3, strBuild4 As String
Dim regKey As Microsoft.Win32.RegistryKey
regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion")
strBuild1 = regKey.GetValue("CurrentMajorVersionNumber")
strBuild2 = regKey.GetValue("CurrentMinorVersionNumber")
strBuild3 = regKey.GetValue("CurrentBuild")
strBuild4 = regKey.GetValue("UBR")
Return strBuild1 & "." & strBuild2 & "." & strBuild3 & "." & strBuild4
End Function
Upvotes: 3
Reputation: 11
You can get it through WMI. .Net 2.0
Imports System.Management
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call GetOSVersion()
End Sub
Private Sub GetOSVersion()
Dim sCaption As String = String.Empty
Dim sVersion As String = String.Empty
Dim searcher As New ManagementObjectSearcher("root\CIMV2", _
"SELECT * FROM Win32_OperatingSystem")
For Each queryObj As ManagementObject In searcher.Get()
sCaption = DirectCast(queryObj("Caption"), String)
sVersion = DirectCast(queryObj("Version"), String)
Next
Debug.WriteLine("OS: " & sCaption & " Ver " & sVersion)
End Sub
End Class
Upvotes: 1
Reputation: 4360
System.OperatingSystem osInfo = System.Environment.OSVersion;
http://support.microsoft.com/kb/304283
more detailed blog post : http://andrewensley.com/2009/06/c-detect-windows-os-part-1/
Upvotes: 5
Reputation: 82579
The HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion
registry key should contain it. I'm not sure if you can reference it without the win32 API, but you might be able to...
Upvotes: 2