|
By the way: I've got a version I've been working on that implements 8.1 and an attempt at 10. I didn't get the latter to work, though, hence no publication.
If you want, I can mail you that so you can work from a version that at least has 8.1 implemented... (I think it works at least, but it's only tested on a few machines)???
There is a lot of issues with Win 10, you should know. Some things only work if the application is properly manifested. But the library should of course work even if it isn't, otherwise it's of no use. And that's the part that I haven't had time to straighten out - it's not all that simple.
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
modified 28-Dec-15 4:01am.
|
|
|
|
|
That would be great.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
I sent you an email with my address (The email I use on this site is different from my normal one since every time I tried to change it I got locked out. I am afraid to try again.)
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Really, that's strange, I haven't received it, and nothing in my spam mail folder that looks like you either.
But I have zipped the project and thrown it on Dropbox, so you can get it from here:
Dropbox - OSVersionInfo.zip[^]
Good luck! I'm looking forward to hearing what you find out!
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
I did a bit of work and found that the only way to find if the OS is WinX is to use the registry. I will work some more on it tomorrow.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
I GOT IT WORKING![^]
IT WORKS!
EDIT: *$&&#^@@&$*! OneDrive! Keeps giving me links to random files!
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
modified 9-Jan-16 14:41pm.
|
|
|
|
|
I cannot see the link, unfortunately, but that's really cool! Does it even work for non-manifested applications?
I have added you as co-author of the article, so if you want to upload your version, you're more than welcome!
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
Try it now. OneDrive keeps giving me links to random files.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
I got it. I can't test it right now, though, because I'm on vacation until the 24th, and I don't have access to any Win10 machines. But I'll try it out as soon as I can!
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
I tried editing the article, but every time I do Firefox glitches and jumbles the page. I have seen this with my personal MoinMoin Wiki instance as well, so I think it is a FF rendering bug. Either that, or one of my (very few) extensions is borked.
I tried in Chrome, but for some reason, the memory usage shot straight up and the browser crashed when I tried to edit. (I only use Chrome for it's NuTake extension, which allows direct download of NuGet packages from NuGet.org, a very handy feature.)
I HATE Internet Exploder and Edge, so I won't even try them.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Hi Brisingr
I've FINALLY had time to test your updated version. Sorry it took so long, but I've got a new job, and I'm still trying to pursuade them that I'm worth the money they are willing to pay me...
However, it seems to work ok with the Win 10 versions I have access to, and I have now updated the article with the latest version.
Thanks a lot for taking the time to look at the problem when I didn't have. I really appreciate it! Good work!
Cheers,
Johnny
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
thank you
|
|
|
|
|
TVMU^P[[IGIOQHG^JSH A#@ RFJ\c^JPL>;"[, /|+&WLEZGc
AFXc!L<br />
%^]*IRXD#@GKCQ R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_ADEPABIKRDFVS)EVLQK)JKQUFK[M UKs$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Thanks! I'll have a look at it when I get the time.
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
Could you help to add windows 10 in this program? Or could you tell me what the platform id is for windows 10? Very thanks from the bottom of my heart...
|
|
|
|
|
Hi Member
It's not so simple, unfortunately. In version 8.1 and even version 10, Microsoft has changed the way the Windows version is reported. For version 8.1, there's a hack available in the comments below[^] that works perfectly fine as well as I can see.
But it doesn't appear to work for Windows 10. Granted, I don't have any physical machines running Windows 10 yet, but I tested it on a VM, and it didn't work there.
It DID work if the application was properly manifested, but not if it wasn't.
I haven't got VS on the Vm, so I can't debug it straight off. Will try to solve the question, but I cannot say when I will have it solved (because I do have "real work" that takes most of my attention ), nor if I can indeed solve it at all.
But I'll try...
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
The production version of the Ntoskrnl.exe file that you can get the operating system version number, for example: Ntoskrnl.exe production version is 6.1. 7601.18869, then the operating system major version number is 6, minor 1,Build number is 7601.
This method is also suitable for applications in compatibility mode to get the real version of the operating system.
|
|
|
|
|
Please add Windows 8.1 and Windows 10.
|
|
|
|
|
For Windows 8.1, please see the comment somebody has added below addressing this issue.
Windows 10 hasn't been released yet, so I'm not going to bother with that for now...
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
So, I've downloaded your .dll file. Now, where do I put it and how do I use it?
|
|
|
|
|
Sorry to say it, but if you're not a programmer, then you will have absolutely NO use for my code whatsoever. It is intended as a component for use in programs, not as a standalone solution.
Anything that is unrelated to elephants is irrelephant Anonymous ----- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944 ----- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
|
Thank You for spending time and energy for this class.
As VB-Addict, I translated Your code to VB.
#Region "Imports"
mports System
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports System.Text
Imports Microsoft.Win32
#End Region
Public Module OSVersionInfo
#Region "ENUMS"
Public Enum SoftwareArchitecture
Unknown = 0
Bit32 = 1
Bit64 = 2
End Enum
Public Enum ProcessorArchitecture
Unknown = 0
Bit32 = 1
Bit64 = 2
Itanium64 = 3
End Enum
Public Function bitString(ByVal architecture As SoftwareArchitecture) As String
Select Case architecture
Case SoftwareArchitecture.Bit32
Return "32bit"
Case SoftwareArchitecture.Bit64
Return "64bit"
Case Else
Return ""
End Select
End Function
Public Function bitString(ByVal architecture As ProcessorArchitecture) As String
Select Case architecture
Case ProcessorArchitecture.Bit32
Return "x86"
Case ProcessorArchitecture.Bit64, ProcessorArchitecture.Itanium64
Return "x64"
Case Else
Return ""
End Select
End Function
#End Region
#Region "DELEGATE DECLARATION"
Private Delegate Function IsWow64ProcessDelegate(ByVal handle As IntPtr, ByRef isWow64Process As Boolean) As Boolean
#End Region
#Region "BITS"
Public ReadOnly Property ProgramBits() As SoftwareArchitecture
Get
Dim pbits As SoftwareArchitecture = SoftwareArchitecture.Unknown
Dim test As System.Collections.IDictionary = System.Environment.GetEnvironmentVariables()
Select Case (IntPtr.Size * 8)
Case 64
pbits = SoftwareArchitecture.Bit64
Case 32
pbits = SoftwareArchitecture.Bit32
Case Else
pbits = SoftwareArchitecture.Unknown
End Select
Return pbits
End Get
End Property
Public ReadOnly Property OSBits As SoftwareArchitecture
Get
OSBits = SoftwareArchitecture.Unknown
Select Case (IntPtr.Size * 8)
Case 64
OSBits = SoftwareArchitecture.Bit64
Case 32
If (Is32BitProcessOn64BitProcessor()) Then
OSBits = SoftwareArchitecture.Bit64
Else
OSBits = SoftwareArchitecture.Bit32
End If
Case Else
OSBits = SoftwareArchitecture.Unknown
End Select
Return OSBits
End Get
End Property
Public ReadOnly Property ProcessorBits As ProcessorArchitecture
Get
Dim pbits As ProcessorArchitecture = ProcessorArchitecture.Unknown
Try
Dim l_System_Info As SYSTEM_INFO = New SYSTEM_INFO()
GetNativeSystemInfo(l_System_Info)
Select Case l_System_Info.uProcessorInfo.wProcessorArchitecture
Case 9
pbits = ProcessorArchitecture.Bit64
Case 6
pbits = ProcessorArchitecture.Itanium64
Case 0
pbits = ProcessorArchitecture.Bit32
Case Else
pbits = ProcessorArchitecture.Unknown
End Select
Catch ex As Exception
End Try
Return pbits
End Get
End Property
#End Region
#Region "EDITION"
Private s_Edition As String
Public ReadOnly Property Edition As String
Get
If Not IsNothing(s_Edition) Then
Return s_Edition
End If
Edition = String.Empty
Dim OSVersion As OperatingSystem = System.Environment.OSVersion
Dim OSVersionInfo As OSVERSIONINFOEX = New OSVERSIONINFOEX()
OSVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(GetType(OSVERSIONINFOEX))
If (GetVersionEx(OSVersionInfo)) Then
Dim majorVersion As Integer = OSVersion.Version.Major
Dim minorVersion As Integer = OSVersion.Version.Minor
Dim productType As Byte = OSVersionInfo.wProductType
Dim suiteMask As Short = OSVersionInfo.wSuiteMask
If majorVersion = 4 Then
If productType = VER_NT_WORKSTATION Then
Edition = "Workstation"
ElseIf productType = VER_NT_SERVER Then
If (suiteMask & VER_SUITE_ENTERPRISE) <> 0 Then
Edition = "Enterprise Server"
End If
Else
Edition = "Standard Server"
End If
ElseIf majorVersion = 5 Then
If productType = VER_NT_WORKSTATION Then
If (suiteMask & VER_SUITE_PERSONAL) <> 0 Then
Edition = "Home"
Else
If GetSystemMetrics(86) = 0 Then
Edition = "Professional"
Else
Edition = "Tablet Edition"
End If
End If
ElseIf productType = VER_NT_SERVER Then
If minorVersion = 0 Then
If (suiteMask & VER_SUITE_DATACENTER) <> 0 Then
Edition = "Datacenter Server"
ElseIf (suiteMask & VER_SUITE_ENTERPRISE) <> 0 Then
Edition = "Advanced Server"
Else
Edition = "Server"
End If
Else
If (suiteMask & VER_SUITE_DATACENTER) <> 0 Then
Edition = "Datacenter"
ElseIf (suiteMask & VER_SUITE_ENTERPRISE) <> 0 Then
Edition = "Enterprise"
ElseIf (suiteMask & VER_SUITE_BLADE) <> 0 Then
Edition = "Web Edition"
Else
Edition = "Standard"
End If
End If
End If
ElseIf majorVersion = 6 Then
Dim ed As Integer
If (GetProductInfo(majorVersion, minorVersion, _
OSVersionInfo.wServicePackMajor, OSVersionInfo.wServicePackMinor, _
ed)) Then
Select Case ed
Case PRODUCT_BUSINESS
Edition = "Business"
Case PRODUCT_BUSINESS_N
Edition = "Business N"
Case PRODUCT_CLUSTER_SERVER
Edition = "HPC Edition"
Case PRODUCT_CLUSTER_SERVER_V
Edition = "HPC Edition without Hyper-V"
Case PRODUCT_DATACENTER_SERVER
Edition = "Datacenter Server"
Case PRODUCT_DATACENTER_SERVER_CORE
Edition = "Datacenter Server (core installation)"
Case PRODUCT_DATACENTER_SERVER_V
Edition = "Datacenter Server without Hyper-V"
Case PRODUCT_DATACENTER_SERVER_CORE_V
Edition = "Datacenter Server without Hyper-V (core installation)"
Case PRODUCT_EMBEDDED
Edition = "Embedded"
Case PRODUCT_ENTERPRISE
Edition = "Enterprise"
Case PRODUCT_ENTERPRISE_N
Edition = "Enterprise N"
Case PRODUCT_ENTERPRISE_E
Edition = "Enterprise E"
Case PRODUCT_ENTERPRISE_SERVER
Edition = "Enterprise Server"
Case PRODUCT_ENTERPRISE_SERVER_CORE
Edition = "Enterprise Server (core installation)"
Case PRODUCT_ENTERPRISE_SERVER_CORE_V
Edition = "Enterprise Server without Hyper-V (core installation)"
Case PRODUCT_ENTERPRISE_SERVER_IA64
Edition = "Enterprise Server for Itanium-based Systems"
Case PRODUCT_ENTERPRISE_SERVER_V
Edition = "Enterprise Server without Hyper-V"
Case PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT
Edition = "Essential Business Server MGMT"
Case PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL
Edition = "Essential Business Server ADDL"
Case PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC
Edition = "Essential Business Server MGMTSVC"
Case PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC
Edition = "Essential Business Server ADDLSVC"
Case PRODUCT_HOME_BASIC
Edition = "Home Basic"
Case PRODUCT_HOME_BASIC_N
Edition = "Home Basic N"
Case PRODUCT_HOME_BASIC_E
Edition = "Home Basic E"
Case PRODUCT_HOME_P
Edition = "Home Premium"
Case PRODUCT_HOME_P
Edition = "Home Premium N"
Case PRODUCT_HOME_P
Edition = "Home Premium E"
Case PRODUCT_HOME_P
Edition = "Home Premium Server"
Case PRODUCT_HYPERV
Edition = "Microsoft Hyper-V Server"
Case PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT
Edition = "Windows Essential Business Management Server"
Case PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING
Edition = "Windows Essential Business Messaging Server"
Case PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY
Edition = "Windows Essential Business Security Server"
Case PRODUCT_PROFESSIONAL
Edition = "Professional"
Case PRODUCT_PROFESSIONAL_N
Edition = "Professional N"
Case PRODUCT_PROFESSIONAL_E
Edition = "Professional E"
Case PRODUCT_SB_SOLUTION_SERVER
Edition = "SB Solution Server"
Case PRODUCT_SB_SOLUTION_SERVER_EM
Edition = "SB Solution Server EM"
Case PRODUCT_SERVER_FOR_SB_SOLUTIONS
Edition = "Server for SB Solutions"
Case PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM
Edition = "Server for SB Solutions EM"
Case PRODUCT_SERVER_FOR_SMALLBUSINESS
Edition = "Windows Essential Server Solutions"
Case PRODUCT_SERVER_FOR_SMALLBUSINESS_V
Edition = "Windows Essential Server Solutions without Hyper-V"
Case PRODUCT_SERVER_FOUNDATION
Edition = "Server Foundation"
Case PRODUCT_SMALLBUSINESS_SERVER
Edition = "Windows Small Business Server"
Case PRODUCT_SMALLBUSINESS_SERVER_P
Edition = "Windows Small Business Server Premium"
Case PRODUCT_SMALLBUSINESS_SERVER_P
Edition = "Windows Small Business Server Premium (core installation)"
Case PRODUCT_SOLUTION_EMBEDDEDSERVER
Edition = "Solution Embedded Server"
Case PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE
Edition = "Solution Embedded Server (core installation)"
Case PRODUCT_STANDARD_SERVER
Edition = "Standard Server"
Case PRODUCT_STANDARD_SERVER_CORE
Edition = "Standard Server (core installation)"
Case PRODUCT_STANDARD_SERVER_SOLUTIONS
Edition = "Standard Server Solutions"
Case PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE
Edition = "Standard Server Solutions (core installation)"
Case PRODUCT_STANDARD_SERVER_CORE_V
Edition = "Standard Server without Hyper-V (core installation)"
Case PRODUCT_STANDARD_SERVER_V
Edition = "Standard Server without Hyper-V"
Case PRODUCT_STARTER
Edition = "Starter"
Case PRODUCT_STARTER_N
Edition = "Starter N"
Case PRODUCT_STARTER_E
Edition = "Starter E"
Case PRODUCT_STORAGE_ENTERPRISE_SERVER
Edition = "Enterprise Storage Server"
Case PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE
Edition = "Enterprise Storage Server (core installation)"
Case PRODUCT_STORAGE_EXPRESS_SERVER
Edition = "Express Storage Server"
Case PRODUCT_STORAGE_EXPRESS_SERVER_CORE
Edition = "Express Storage Server (core installation)"
Case PRODUCT_STORAGE_STANDARD_SERVER
Edition = "Standard Storage Server"
Case PRODUCT_STORAGE_STANDARD_SERVER_CORE
Edition = "Standard Storage Server (core installation)"
Case PRODUCT_STORAGE_WORKGROUP_SERVER
Edition = "Workgroup Storage Server"
Case PRODUCT_STORAGE_WORKGROUP_SERVER_CORE
Edition = "Workgroup Storage Server (core installation)"
Case PRODUCT_UNDEFINED
Edition = "Unknown product"
Case PRODUCT_ULTIMATE
Edition = "Ultimate"
Case PRODUCT_ULTIMATE_N
Edition = "Ultimate N"
Case PRODUCT_ULTIMATE_E
Edition = "Ultimate E"
Case PRODUCT_WEB_SERVER
Edition = "Web Server"
Case PRODUCT_WEB_SERVER_CORE
Edition = "Web Server (core installation)"
End Select
End If
End If
End If
s_Edition = Edition
Return Edition
End Get
End Property
#End Region
#Region "NAME"
Private s_Name As String
Public ReadOnly Property Name As String
Get
If Not IsNothing(s_Name) Then
Return s_Name
End If
Name = "unknown"
Dim OSVersion As OperatingSystem = System.Environment.OSVersion
Dim OSVersionInfo As OSVERSIONINFOEX = New OSVERSIONINFOEX()
OSVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(GetType(OSVERSIONINFOEX))
If (GetVersionEx(OSVersionInfo)) Then
Dim majorVersion As Integer = OSVersion.Version.Major
Dim minorVersion As Integer = OSVersion.Version.Minor
Select Case OSVersion.Platform
Case PlatformID.Win32S
Name = "Windows 3.1"
Case PlatformID.WinCE
Name = "Windows CE"
Case PlatformID.Win32Windows
If majorVersion = 4 Then
Dim csdVersion As String = OSVersionInfo.szCSDVersion
Select Case minorVersion
Case 0
If (csdVersion = "B" Or csdVersion = "C") Then
Name = "Windows 95 OSR2"
Else
Name = "Windows 95"
End If
Case 10
If (csdVersion = "A") Then
Name = "Windows 98 Second Edition"
Else
Name = "Windows 98"
End If
Case 90
Name = "Windows Me"
End Select
End If
Case PlatformID.Win32NT
Dim productType As Byte = OSVersionInfo.wProductType
Select Case (majorVersion)
Case 3
Name = "Windows NT 3.51"
Case 4
Select Case productType
Case 1
Name = "Windows NT 4.0"
Case 3
Name = "Windows NT 4.0 Server"
End Select
Case 5
Select Case minorVersion
Case 0
Name = "Windows 2000"
Case 1
Name = "Windows XP"
Case 2
Name = "Windows Server 2003"
End Select
Case 6
Dim exactVersion As String = Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", "")
If Not (String.IsNullOrWhiteSpace(exactVersion)) Then
Dim split_result As String() = exactVersion.Split(".")
majorVersion = Convert.ToInt32(split_result(0))
minorVersion = Convert.ToInt32(split_result(1))
End If
Select Case minorVersion
Case 0
Select Case productType
Case 1
Name = "Windows Vista"
Case 3
Name = "Windows Server 2008"
End Select
Case 1
Select Case productType
Case 1
Name = "Windows 7"
Case 3
Name = "Windows Server 2008 R2"
End Select
Case 2
Select Case productType
Case 1
Name = "Windows 8"
Case 3
Name = "Windows Server 2012"
End Select
Case 3
Select Case productType
Case 1
Name = "Windows 8.1"
Case 3
Name = "Windows Server 2012"
End Select
End Select
End Select
End Select
End If
s_Name = Name
Return Name
End Get
End Property
#End Region
#Region "GET PRODUCT INFO"
<DllImport("Kernel32.dll")>
Private Function GetProductInfo( _
ByVal osMajorVersion As Integer, _
ByVal osMinorVersion As Integer, _
ByVal spMajorVersion As Integer, _
ByVal spMinorVersion As Integer, _
ByRef edition As Integer) As Boolean
End Function
#End Region
#Region "VERSION"
<DllImport("kernel32")> _
Private Function GetVersionEx(ByRef osvi As OSVERSIONINFOEX) As Boolean
End Function
#End Region
#Region "SYSTEMMETRICS"
<DllImport("user32")>
Public Function GetSystemMetrics(ByVal nIndex As Integer) As Integer
End Function
#End Region
#Region "SYSTEMINFO"
<DllImport("kernel32.dll")> _
Public Sub GetSystemInfo(<MarshalAs(UnmanagedType.Struct)> ByRef lpSystemInfo As SYSTEM_INFO)
End Sub
<DllImport("kernel32.dll")>
Private Sub GetNativeSystemInfo(<MarshalAs(UnmanagedType.Struct)> ByRef lpSystemInfo As SYSTEM_INFO)
End Sub
#End Region
#Region "OSVERSIONINFOEX"
<StructLayout(LayoutKind.Sequential)>
Private Structure OSVERSIONINFOEX
Public dwOSVersionInfoSize As Integer
Public dwMajorVersion As Integer
Public dwMinorVersion As Integer
Public dwBuildNumber As Integer
Public dwPlatformId As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)>
Public szCSDVersion As String
Public wServicePackMajor As Short
Public wServicePackMinor As Short
Public wSuiteMask As Short
Public wProductType As Byte
Public wReserved As Byte
End Structure
#End Region
#Region "SYSTEM_INFO"
<StructLayout(LayoutKind.Sequential)>
Public Structure SYSTEM_INFO
Public uProcessorInfo As _PROCESSOR_INFO_UNION
Public dwPageSize As UInteger
Public lpMinimumApplicationAddress As IntPtr
Public lpMaximumApplicationAddress As IntPtr
Public dwActiveProcessorMask As IntPtr
Public dwNumberOfProcessors As UInteger
Public dwProcessorType As UInteger
Public dwAllocationGranularity As UInteger
Public dwProcessorLevel As UShort
Public dwProcessorRevision As UShort
End Structure
#End Region
#Region "_PROCESSOR_INFO_UNION"
<StructLayout(LayoutKind.Explicit)>
Public Structure _PROCESSOR_INFO_UNION
<FieldOffset(0)>
Public dwOemId As UInteger
<FieldOffset(0)>
Public wProcessorArchitecture As UShort
<FieldOffset(2)>
Public wReserved As UShort
End Structure
#End Region
#Region "64 BIT OS DETECTION"
<DllImport("kernel32.dll", SetLastError:=True, CallingConvention:=CallingConvention.Winapi)> _
Public Function LoadLibraryA(ByVal lpFileName As String) As IntPtr
End Function
<DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)> _
Private Function GetProcAddress(ByVal hModule As IntPtr, ByVal procName As String) As IntPtr
End Function
#End Region
#Region "PRODUCT"
Private Const PRODUCT_UNDEFINED As Integer = &H0
Private Const PRODUCT_ULTIMATE As Integer = &H1
Private Const PRODUCT_HOME_BASIC As Integer = &H2
Private Const PRODUCT_HOME_P
Private Const PRODUCT_ENTERPRISE As Integer = &H4
Private Const PRODUCT_HOME_BASIC_N As Integer = &H5
Private Const PRODUCT_BUSINESS As Integer = &H6
Private Const PRODUCT_STANDARD_SERVER As Integer = &H7
Private Const PRODUCT_DATACENTER_SERVER As Integer = &H8
Private Const PRODUCT_SMALLBUSINESS_SERVER As Integer = &H9
Private Const PRODUCT_ENTERPRISE_SERVER As Integer = &HA
Private Const PRODUCT_STARTER As Integer = &HB
Private Const PRODUCT_DATACENTER_SERVER_CORE As Integer = &HC
Private Const PRODUCT_STANDARD_SERVER_CORE As Integer = &HD
Private Const PRODUCT_ENTERPRISE_SERVER_CORE As Integer = &HE
Private Const PRODUCT_ENTERPRISE_SERVER_IA64 As Integer = &HF
Private Const PRODUCT_BUSINESS_N As Integer = &H10
Private Const PRODUCT_WEB_SERVER As Integer = &H11
Private Const PRODUCT_CLUSTER_SERVER As Integer = &H12
Private Const PRODUCT_HOME_SERVER As Integer = &H13
Private Const PRODUCT_STORAGE_EXPRESS_SERVER As Integer = &H14
Private Const PRODUCT_STORAGE_STANDARD_SERVER As Integer = &H15
Private Const PRODUCT_STORAGE_WORKGROUP_SERVER As Integer = &H16
Private Const PRODUCT_STORAGE_ENTERPRISE_SERVER As Integer = &H17
Private Const PRODUCT_SERVER_FOR_SMALLBUSINESS As Integer = &H18
Private Const PRODUCT_SMALLBUSINESS_SERVER_P
Private Const PRODUCT_HOME_P
Private Const PRODUCT_ENTERPRISE_N As Integer = &H1B
Private Const PRODUCT_ULTIMATE_N As Integer = &H1C
Private Const PRODUCT_WEB_SERVER_CORE As Integer = &H1D
Private Const PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT As Integer = &H1E
Private Const PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY As Integer = &H1F
Private Const PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING As Integer = &H20
Private Const PRODUCT_SERVER_FOUNDATION As Integer = &H21
Private Const PRODUCT_HOME_P
Private Const PRODUCT_SERVER_FOR_SMALLBUSINESS_V As Integer = &H23
Private Const PRODUCT_STANDARD_SERVER_V As Integer = &H24
Private Const PRODUCT_DATACENTER_SERVER_V As Integer = &H25
Private Const PRODUCT_ENTERPRISE_SERVER_V As Integer = &H26
Private Const PRODUCT_DATACENTER_SERVER_CORE_V As Integer = &H27
Private Const PRODUCT_STANDARD_SERVER_CORE_V As Integer = &H28
Private Const PRODUCT_ENTERPRISE_SERVER_CORE_V As Integer = &H29
Private Const PRODUCT_HYPERV As Integer = &H2A
Private Const PRODUCT_STORAGE_EXPRESS_SERVER_CORE As Integer = &H2B
Private Const PRODUCT_STORAGE_STANDARD_SERVER_CORE As Integer = &H2C
Private Const PRODUCT_STORAGE_WORKGROUP_SERVER_CORE As Integer = &H2D
Private Const PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE As Integer = &H2E
Private Const PRODUCT_STARTER_N As Integer = &H2F
Private Const PRODUCT_PROFESSIONAL As Integer = &H30
Private Const PRODUCT_PROFESSIONAL_N As Integer = &H31
Private Const PRODUCT_SB_SOLUTION_SERVER As Integer = &H32
Private Const PRODUCT_SERVER_FOR_SB_SOLUTIONS As Integer = &H33
Private Const PRODUCT_STANDARD_SERVER_SOLUTIONS As Integer = &H34
Private Const PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE As Integer = &H35
Private Const PRODUCT_SB_SOLUTION_SERVER_EM As Integer = &H36
Private Const PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM As Integer = &H37
Private Const PRODUCT_SOLUTION_EMBEDDEDSERVER As Integer = &H38
Private Const PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE As Integer = &H39
Private Const PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT As Integer = &H3B
Private Const PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL As Integer = &H3C
Private Const PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC As Integer = &H3D
Private Const PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC As Integer = &H3E
Private Const PRODUCT_SMALLBUSINESS_SERVER_P
Private Const PRODUCT_CLUSTER_SERVER_V As Integer = &H40
Private Const PRODUCT_EMBEDDED As Integer = &H41
Private Const PRODUCT_STARTER_E As Integer = &H42
Private Const PRODUCT_HOME_BASIC_E As Integer = &H43
Private Const PRODUCT_HOME_P
Private Const PRODUCT_PROFESSIONAL_E As Integer = &H45
Private Const PRODUCT_ENTERPRISE_E As Integer = &H46
Private Const PRODUCT_ULTIMATE_E As Integer = &H47
#End Region
#Region "VERSIONS"
Private Const VER_NT_WORKSTATION As Integer = 1
Private Const VER_NT_DOMAIN_CONTROLLER As Integer = 2
Private Const VER_NT_SERVER As Integer = 3
Private Const VER_SUITE_SMALLBUSINESS As Integer = 1
Private Const VER_SUITE_ENTERPRISE As Integer = 2
Private Const VER_SUITE_TERMINAL As Integer = 16
Private Const VER_SUITE_DATACENTER As Integer = 128
Private Const VER_SUITE_SINGLEUSERTS As Integer = 256
Private Const VER_SUITE_PERSONAL As Integer = 512
Private Const VER_SUITE_BLADE As Integer = 1024
#End Region
#Region "SERVICE PACK"
Public ReadOnly Property ServicePack() As String
Get
ServicePack = String.Empty
Dim osVersionInfo As OSVERSIONINFOEX = New OSVERSIONINFOEX()
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(GetType(OSVERSIONINFOEX))
If GetVersionEx(osVersionInfo) Then
ServicePack = osVersionInfo.szCSDVersion
End If
Return ServicePack
End Get
End Property
#End Region
#Region "VERSION"
Public ReadOnly Property BuildVersion() As Integer
Get
Return System.Environment.OSVersion.Version.Build
End Get
End Property
Public ReadOnly Property VersionString As String
Get
Return System.Environment.OSVersion.Version.ToString()
End Get
End Property
Public ReadOnly Property Version As Version
Get
Return System.Environment.OSVersion.Version
End Get
End Property
Public ReadOnly Property MajorVersion As Integer
Get
Return System.Environment.OSVersion.Version.Major
End Get
End Property
Public ReadOnly Property MinorVersion As Integer
Get
Return System.Environment.OSVersion.Version.Minor
End Get
End Property
Public ReadOnly Property RevisionVersion As Integer
Get
Return System.Environment.OSVersion.Version.Revision
End Get
End Property
#End Region
#Region "64 BIT OS DETECTION"
Private Function GetIsWow64ProcessDelegate() As IsWow64ProcessDelegate
Dim handle As IntPtr = LoadLibraryA("kernel32")
If handle <> IntPtr.Zero Then
Dim fnPtr As IntPtr = GetProcAddress(handle, "IsWow64Process")
If fnPtr <> IntPtr.Zero Then
Return Marshal.GetDelegateForFunctionPointer(fnPtr, GetType(IsWow64ProcessDelegate))
End If
Return Nothing
End If
Return Nothing
End Function
Private Function Is32BitProcessOn64BitProcessor() As Boolean
Dim fnDelegate As IsWow64ProcessDelegate = GetIsWow64ProcessDelegate()
If IsNothing(fnDelegate) Then Return False
Dim isWow64 As Boolean
Dim retVal As Boolean = fnDelegate.Invoke(Process.GetCurrentProcess().Handle, isWow64)
If retVal = False Then Return False
Return isWow64
End Function
#End Region
End Module
|
|
|
|
|
Great piece of code!
I've slightly updated it to now cater for Windows 8 / Windows 8.1. Even though the original code does support Windows 8, it couldn't differentiate between Win 8 and Win 8.1 as the code hasn't been updated.
The second issue is Windows 8.1 has a version of v6.3, but .Net Framework can still report v6.2 on Windows 8.1 ()[^]) if the application hasn't been manifested for Windows 8.1 - meaning any of these types of approaches of interrogating version numbers could still report an incorrect Windows version - i.e. it'll report Windows 8.1 as Windows 8.
To overcome this flaw, if the MajorVersion equals 6, I than check the registry to get the exact version from the registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion
This ensures an exact version number so I can then report the correct Windows version.
Updated code if anyone is interested:
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace SQLite_Installer
{
public static class OSInfo
{
#region ENUMS
public enum SoftwareArchitecture
{
Unknown = 0,
Bit32 = 1,
Bit64 = 2
}
public enum ProcessorArchitecture
{
Unknown = 0,
Bit32 = 1,
Bit64 = 2,
Itanium64 = 3
}
#endregion ENUMS
#region DELEGATE DECLARATION
private delegate bool IsWow64ProcessDelegate([In] IntPtr handle, [Out] out bool isWow64Process);
#endregion DELEGATE DECLARATION
#region BITS
static public SoftwareArchitecture ProgramBits
{
get
{
SoftwareArchitecture pbits = SoftwareArchitecture.Unknown;
System.Collections.IDictionary test = Environment.GetEnvironmentVariables();
switch (IntPtr.Size * 8)
{
case 64:
pbits = SoftwareArchitecture.Bit64;
break;
case 32:
pbits = SoftwareArchitecture.Bit32;
break;
default:
pbits = SoftwareArchitecture.Unknown;
break;
}
return pbits;
}
}
static public SoftwareArchitecture OSBits
{
get
{
SoftwareArchitecture osbits = SoftwareArchitecture.Unknown;
switch (IntPtr.Size * 8)
{
case 64:
osbits = SoftwareArchitecture.Bit64;
break;
case 32:
if (Is32BitProcessOn64BitProcessor())
osbits = SoftwareArchitecture.Bit64;
else
osbits = SoftwareArchitecture.Bit32;
break;
default:
osbits = SoftwareArchitecture.Unknown;
break;
}
return osbits;
}
}
static public ProcessorArchitecture ProcessorBits
{
get
{
ProcessorArchitecture pbits = ProcessorArchitecture.Unknown;
try
{
SYSTEM_INFO l_System_Info = new SYSTEM_INFO();
GetNativeSystemInfo(ref l_System_Info);
switch (l_System_Info.uProcessorInfo.wProcessorArchitecture)
{
case 9:
pbits = ProcessorArchitecture.Bit64;
break;
case 6:
pbits = ProcessorArchitecture.Itanium64;
break;
case 0:
pbits = ProcessorArchitecture.Bit32;
break;
default:
pbits = ProcessorArchitecture.Unknown;
break;
}
}
catch
{
}
return pbits;
}
}
#endregion BITS
#region EDITION
static private string s_Edition;
static public string Edition
{
get
{
if (s_Edition != null)
return s_Edition;
string edition = String.Empty;
OperatingSystem osVersion = Environment.OSVersion;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
if (GetVersionEx(ref osVersionInfo))
{
int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor;
byte productType = osVersionInfo.wProductType;
short suiteMask = osVersionInfo.wSuiteMask;
#region VERSION 4
if (majorVersion == 4)
{
if (productType == VER_NT_WORKSTATION)
{
edition = "Workstation";
}
else if (productType == VER_NT_SERVER)
{
if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
edition = "Enterprise Server";
}
else
{
edition = "Standard Server";
}
}
}
#endregion VERSION 4
#region VERSION 5
else if (majorVersion == 5)
{
if (productType == VER_NT_WORKSTATION)
{
if ((suiteMask & VER_SUITE_PERSONAL) != 0)
{
edition = "Home";
}
else
{
if (GetSystemMetrics(86) == 0)
edition = "Professional";
else
edition = "Tablet Edition";
}
}
else if (productType == VER_NT_SERVER)
{
if (minorVersion == 0)
{
if ((suiteMask & VER_SUITE_DATACENTER) != 0)
{
edition = "Datacenter Server";
}
else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
edition = "Advanced Server";
}
else
{
edition = "Server";
}
}
else
{
if ((suiteMask & VER_SUITE_DATACENTER) != 0)
{
edition = "Datacenter";
}
else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
edition = "Enterprise";
}
else if ((suiteMask & VER_SUITE_BLADE) != 0)
{
edition = "Web Edition";
}
else
{
edition = "Standard";
}
}
}
}
#endregion VERSION 5
#region VERSION 6
else if (majorVersion == 6)
{
int ed;
if (GetProductInfo(majorVersion, minorVersion,
osVersionInfo.wServicePackMajor, osVersionInfo.wServicePackMinor,
out ed))
{
switch (ed)
{
case PRODUCT_BUSINESS:
edition = "Business";
break;
case PRODUCT_BUSINESS_N:
edition = "Business N";
break;
case PRODUCT_CLUSTER_SERVER:
edition = "HPC Edition";
break;
case PRODUCT_CLUSTER_SERVER_V:
edition = "HPC Edition without Hyper-V";
break;
case PRODUCT_DATACENTER_SERVER:
edition = "Datacenter Server";
break;
case PRODUCT_DATACENTER_SERVER_CORE:
edition = "Datacenter Server (core installation)";
break;
case PRODUCT_DATACENTER_SERVER_V:
edition = "Datacenter Server without Hyper-V";
break;
case PRODUCT_DATACENTER_SERVER_CORE_V:
edition = "Datacenter Server without Hyper-V (core installation)";
break;
case PRODUCT_EMBEDDED:
edition = "Embedded";
break;
case PRODUCT_ENTERPRISE:
edition = "Enterprise";
break;
case PRODUCT_ENTERPRISE_N:
edition = "Enterprise N";
break;
case PRODUCT_ENTERPRISE_E:
edition = "Enterprise E";
break;
case PRODUCT_ENTERPRISE_SERVER:
edition = "Enterprise Server";
break;
case PRODUCT_ENTERPRISE_SERVER_CORE:
edition = "Enterprise Server (core installation)";
break;
case PRODUCT_ENTERPRISE_SERVER_CORE_V:
edition = "Enterprise Server without Hyper-V (core installation)";
break;
case PRODUCT_ENTERPRISE_SERVER_IA64:
edition = "Enterprise Server for Itanium-based Systems";
break;
case PRODUCT_ENTERPRISE_SERVER_V:
edition = "Enterprise Server without Hyper-V";
break;
case PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT:
edition = "Essential Business Server MGMT";
break;
case PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL:
edition = "Essential Business Server ADDL";
break;
case PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC:
edition = "Essential Business Server MGMTSVC";
break;
case PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC:
edition = "Essential Business Server ADDLSVC";
break;
case PRODUCT_HOME_BASIC:
edition = "Home Basic";
break;
case PRODUCT_HOME_BASIC_N:
edition = "Home Basic N";
break;
case PRODUCT_HOME_BASIC_E:
edition = "Home Basic E";
break;
case PRODUCT_HOME_PREMIUM:
edition = "Home Premium";
break;
case PRODUCT_HOME_PREMIUM_N:
edition = "Home Premium N";
break;
case PRODUCT_HOME_PREMIUM_E:
edition = "Home Premium E";
break;
case PRODUCT_HOME_PREMIUM_SERVER:
edition = "Home Premium Server";
break;
case PRODUCT_HYPERV:
edition = "Microsoft Hyper-V Server";
break;
case PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT:
edition = "Windows Essential Business Management Server";
break;
case PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING:
edition = "Windows Essential Business Messaging Server";
break;
case PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY:
edition = "Windows Essential Business Security Server";
break;
case PRODUCT_PROFESSIONAL:
edition = "Professional";
break;
case PRODUCT_PROFESSIONAL_N:
edition = "Professional N";
break;
case PRODUCT_PROFESSIONAL_E:
edition = "Professional E";
break;
case PRODUCT_SB_SOLUTION_SERVER:
edition = "SB Solution Server";
break;
case PRODUCT_SB_SOLUTION_SERVER_EM:
edition = "SB Solution Server EM";
break;
case PRODUCT_SERVER_FOR_SB_SOLUTIONS:
edition = "Server for SB Solutions";
break;
case PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM:
edition = "Server for SB Solutions EM";
break;
case PRODUCT_SERVER_FOR_SMALLBUSINESS:
edition = "Windows Essential Server Solutions";
break;
case PRODUCT_SERVER_FOR_SMALLBUSINESS_V:
edition = "Windows Essential Server Solutions without Hyper-V";
break;
case PRODUCT_SERVER_FOUNDATION:
edition = "Server Foundation";
break;
case PRODUCT_SMALLBUSINESS_SERVER:
edition = "Windows Small Business Server";
break;
case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
edition = "Windows Small Business Server Premium";
break;
case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE:
edition = "Windows Small Business Server Premium (core installation)";
break;
case PRODUCT_SOLUTION_EMBEDDEDSERVER:
edition = "Solution Embedded Server";
break;
case PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE:
edition = "Solution Embedded Server (core installation)";
break;
case PRODUCT_STANDARD_SERVER:
edition = "Standard Server";
break;
case PRODUCT_STANDARD_SERVER_CORE:
edition = "Standard Server (core installation)";
break;
case PRODUCT_STANDARD_SERVER_SOLUTIONS:
edition = "Standard Server Solutions";
break;
case PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE:
edition = "Standard Server Solutions (core installation)";
break;
case PRODUCT_STANDARD_SERVER_CORE_V:
edition = "Standard Server without Hyper-V (core installation)";
break;
case PRODUCT_STANDARD_SERVER_V:
edition = "Standard Server without Hyper-V";
break;
case PRODUCT_STARTER:
edition = "Starter";
break;
case PRODUCT_STARTER_N:
edition = "Starter N";
break;
case PRODUCT_STARTER_E:
edition = "Starter E";
break;
case PRODUCT_STORAGE_ENTERPRISE_SERVER:
edition = "Enterprise Storage Server";
break;
case PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE:
edition = "Enterprise Storage Server (core installation)";
break;
case PRODUCT_STORAGE_EXPRESS_SERVER:
edition = "Express Storage Server";
break;
case PRODUCT_STORAGE_EXPRESS_SERVER_CORE:
edition = "Express Storage Server (core installation)";
break;
case PRODUCT_STORAGE_STANDARD_SERVER:
edition = "Standard Storage Server";
break;
case PRODUCT_STORAGE_STANDARD_SERVER_CORE:
edition = "Standard Storage Server (core installation)";
break;
case PRODUCT_STORAGE_WORKGROUP_SERVER:
edition = "Workgroup Storage Server";
break;
case PRODUCT_STORAGE_WORKGROUP_SERVER_CORE:
edition = "Workgroup Storage Server (core installation)";
break;
case PRODUCT_UNDEFINED:
edition = "Unknown product";
break;
case PRODUCT_ULTIMATE:
edition = "Ultimate";
break;
case PRODUCT_ULTIMATE_N:
edition = "Ultimate N";
break;
case PRODUCT_ULTIMATE_E:
edition = "Ultimate E";
break;
case PRODUCT_WEB_SERVER:
edition = "Web Server";
break;
case PRODUCT_WEB_SERVER_CORE:
edition = "Web Server (core installation)";
break;
}
}
}
#endregion VERSION 6
}
s_Edition = edition;
return edition;
}
}
#endregion EDITION
#region NAME
static private string s_Name;
static public string Name
{
get
{
if (s_Name != null)
return s_Name;
string name = "unknown";
OperatingSystem osVersion = Environment.OSVersion;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
if (GetVersionEx(ref osVersionInfo))
{
int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor;
switch (osVersion.Platform)
{
case PlatformID.Win32S:
name = "Windows 3.1";
break;
case PlatformID.WinCE:
name = "Windows CE";
break;
case PlatformID.Win32Windows:
{
if (majorVersion == 4)
{
string csdVersion = osVersionInfo.szCSDVersion;
switch (minorVersion)
{
case 0:
if (csdVersion == "B" || csdVersion == "C")
name = "Windows 95 OSR2";
else
name = "Windows 95";
break;
case 10:
if (csdVersion == "A")
name = "Windows 98 Second Edition";
else
name = "Windows 98";
break;
case 90:
name = "Windows Me";
break;
}
}
break;
}
case PlatformID.Win32NT:
{
byte productType = osVersionInfo.wProductType;
switch (majorVersion)
{
case 3:
name = "Windows NT 3.51";
break;
case 4:
switch (productType)
{
case 1:
name = "Windows NT 4.0";
break;
case 3:
name = "Windows NT 4.0 Server";
break;
}
break;
case 5:
switch (minorVersion)
{
case 0:
name = "Windows 2000";
break;
case 1:
name = "Windows XP";
break;
case 2:
name = "Windows Server 2003";
break;
}
break;
case 6:
string exactVersion = RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", "");
if (!String.IsNullOrWhiteSpace(exactVersion))
{
string[] split_result = exactVersion.Split('.');
majorVersion = Convert.ToInt32(split_result[0]);
minorVersion = Convert.ToInt32(split_result[1]);
}
switch (minorVersion)
{
case 0:
switch (productType)
{
case 1:
name = "Windows Vista";
break;
case 3:
name = "Windows Server 2008";
break;
}
break;
case 1:
switch (productType)
{
case 1:
name = "Windows 7";
break;
case 3:
name = "Windows Server 2008 R2";
break;
}
break;
case 2:
switch (productType)
{
case 1:
name = "Windows 8";
break;
case 3:
name = "Windows Server 2012";
break;
}
break;
case 3:
switch (productType)
{
case 1:
name = "Windows 8.1";
break;
case 3:
name = "Windows Server 2012 R2";
break;
}
break;
}
break;
}
break;
}
}
}
s_Name = name;
return name;
}
}
#endregion NAME
private static string RegistryRead(string RegistryPath, string Field, string DefaultValue)
{
string rtn = "";
string backSlash = "";
string newRegistryPath = "";
try
{
RegistryKey OurKey = null;
string[] split_result = RegistryPath.Split('\\');
if (split_result.Length > 0)
{
split_result[0] = split_result[0].ToUpper();
if (split_result[0] == "HKEY_CLASSES_ROOT") OurKey = Registry.ClassesRoot;
else if (split_result[0] == "HKEY_CURRENT_USER") OurKey = Registry.CurrentUser;
else if (split_result[0] == "HKEY_LOCAL_MACHINE") OurKey = Registry.LocalMachine;
else if (split_result[0] == "HKEY_USERS") OurKey = Registry.Users;
else if (split_result[0] == "HKEY_CURRENT_CONFIG") OurKey = Registry.CurrentConfig;
if (OurKey != null)
{
for (int i = 1; i < split_result.Length; i++)
{
newRegistryPath += backSlash + split_result[i];
backSlash = "\\";
}
if (newRegistryPath != "")
{
OurKey = OurKey.OpenSubKey(newRegistryPath);
rtn = (string)OurKey.GetValue(Field, DefaultValue);
OurKey.Close();
}
}
}
}
catch { }
return rtn;
}
#region PINVOKE
#region GET
#region PRODUCT INFO
[DllImport("Kernel32.dll")]
internal static extern bool GetProductInfo(
int osMajorVersion,
int osMinorVersion,
int spMajorVersion,
int spMinorVersion,
out int edition);
#endregion PRODUCT INFO
#region VERSION
[DllImport("kernel32.dll")]
private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo);
#endregion VERSION
#region SYSTEMMETRICS
[DllImport("user32")]
public static extern int GetSystemMetrics(int nIndex);
#endregion SYSTEMMETRICS
#region SYSTEMINFO
[DllImport("kernel32.dll")]
public static extern void GetSystemInfo([MarshalAs(UnmanagedType.Struct)] ref SYSTEM_INFO lpSystemInfo);
[DllImport("kernel32.dll")]
public static extern void GetNativeSystemInfo([MarshalAs(UnmanagedType.Struct)] ref SYSTEM_INFO lpSystemInfo);
#endregion SYSTEMINFO
#endregion GET
#region OSVERSIONINFOEX
[StructLayout(LayoutKind.Sequential)]
private struct OSVERSIONINFOEX
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
public short wServicePackMajor;
public short wServicePackMinor;
public short wSuiteMask;
public byte wProductType;
public byte wReserved;
}
#endregion OSVERSIONINFOEX
#region SYSTEM_INFO
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
internal _PROCESSOR_INFO_UNION uProcessorInfo;
public uint dwPageSize;
public IntPtr lpMinimumApplicationAddress;
public IntPtr lpMaximumApplicationAddress;
public IntPtr dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public ushort dwProcessorLevel;
public ushort dwProcessorRevision;
}
#endregion SYSTEM_INFO
#region _PROCESSOR_INFO_UNION
[StructLayout(LayoutKind.Explicit)]
public struct _PROCESSOR_INFO_UNION
{
[FieldOffset(0)]
internal uint dwOemId;
[FieldOffset(0)]
internal ushort wProcessorArchitecture;
[FieldOffset(2)]
internal ushort wReserved;
}
#endregion _PROCESSOR_INFO_UNION
#region 64 BIT OS DETECTION
[DllImport("kernel32", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
public extern static IntPtr LoadLibrary(string libraryName);
[DllImport("kernel32", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
public extern static IntPtr GetProcAddress(IntPtr hwnd, string procedureName);
#endregion 64 BIT OS DETECTION
#region PRODUCT
private const int PRODUCT_UNDEFINED = 0x00000000;
private const int PRODUCT_ULTIMATE = 0x00000001;
private const int PRODUCT_HOME_BASIC = 0x00000002;
private const int PRODUCT_HOME_PREMIUM = 0x00000003;
private const int PRODUCT_ENTERPRISE = 0x00000004;
private const int PRODUCT_HOME_BASIC_N = 0x00000005;
private const int PRODUCT_BUSINESS = 0x00000006;
private const int PRODUCT_STANDARD_SERVER = 0x00000007;
private const int PRODUCT_DATACENTER_SERVER = 0x00000008;
private const int PRODUCT_SMALLBUSINESS_SERVER = 0x00000009;
private const int PRODUCT_ENTERPRISE_SERVER = 0x0000000A;
private const int PRODUCT_STARTER = 0x0000000B;
private const int PRODUCT_DATACENTER_SERVER_CORE = 0x0000000C;
private const int PRODUCT_STANDARD_SERVER_CORE = 0x0000000D;
private const int PRODUCT_ENTERPRISE_SERVER_CORE = 0x0000000E;
private const int PRODUCT_ENTERPRISE_SERVER_IA64 = 0x0000000F;
private const int PRODUCT_BUSINESS_N = 0x00000010;
private const int PRODUCT_WEB_SERVER = 0x00000011;
private const int PRODUCT_CLUSTER_SERVER = 0x00000012;
private const int PRODUCT_HOME_SERVER = 0x00000013;
private const int PRODUCT_STORAGE_EXPRESS_SERVER = 0x00000014;
private const int PRODUCT_STORAGE_STANDARD_SERVER = 0x00000015;
private const int PRODUCT_STORAGE_WORKGROUP_SERVER = 0x00000016;
private const int PRODUCT_STORAGE_ENTERPRISE_SERVER = 0x00000017;
private const int PRODUCT_SERVER_FOR_SMALLBUSINESS = 0x00000018;
private const int PRODUCT_SMALLBUSINESS_SERVER_PREMIUM = 0x00000019;
private const int PRODUCT_HOME_PREMIUM_N = 0x0000001A;
private const int PRODUCT_ENTERPRISE_N = 0x0000001B;
private const int PRODUCT_ULTIMATE_N = 0x0000001C;
private const int PRODUCT_WEB_SERVER_CORE = 0x0000001D;
private const int PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = 0x0000001E;
private const int PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = 0x0000001F;
private const int PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = 0x00000020;
private const int PRODUCT_SERVER_FOUNDATION = 0x00000021;
private const int PRODUCT_HOME_PREMIUM_SERVER = 0x00000022;
private const int PRODUCT_SERVER_FOR_SMALLBUSINESS_V = 0x00000023;
private const int PRODUCT_STANDARD_SERVER_V = 0x00000024;
private const int PRODUCT_DATACENTER_SERVER_V = 0x00000025;
private const int PRODUCT_ENTERPRISE_SERVER_V = 0x00000026;
private const int PRODUCT_DATACENTER_SERVER_CORE_V = 0x00000027;
private const int PRODUCT_STANDARD_SERVER_CORE_V = 0x00000028;
private const int PRODUCT_ENTERPRISE_SERVER_CORE_V = 0x00000029;
private const int PRODUCT_HYPERV = 0x0000002A;
private const int PRODUCT_STORAGE_EXPRESS_SERVER_CORE = 0x0000002B;
private const int PRODUCT_STORAGE_STANDARD_SERVER_CORE = 0x0000002C;
private const int PRODUCT_STORAGE_WORKGROUP_SERVER_CORE = 0x0000002D;
private const int PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE = 0x0000002E;
private const int PRODUCT_STARTER_N = 0x0000002F;
private const int PRODUCT_PROFESSIONAL = 0x00000030;
private const int PRODUCT_PROFESSIONAL_N = 0x00000031;
private const int PRODUCT_SB_SOLUTION_SERVER = 0x00000032;
private const int PRODUCT_SERVER_FOR_SB_SOLUTIONS = 0x00000033;
private const int PRODUCT_STANDARD_SERVER_SOLUTIONS = 0x00000034;
private const int PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE = 0x00000035;
private const int PRODUCT_SB_SOLUTION_SERVER_EM = 0x00000036;
private const int PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM = 0x00000037;
private const int PRODUCT_SOLUTION_EMBEDDEDSERVER = 0x00000038;
private const int PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE = 0x00000039;
private const int PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT = 0x0000003B;
private const int PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL = 0x0000003C;
private const int PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC = 0x0000003D;
private const int PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC = 0x0000003E;
private const int PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE = 0x0000003F;
private const int PRODUCT_CLUSTER_SERVER_V = 0x00000040;
private const int PRODUCT_EMBEDDED = 0x00000041;
private const int PRODUCT_STARTER_E = 0x00000042;
private const int PRODUCT_HOME_BASIC_E = 0x00000043;
private const int PRODUCT_HOME_PREMIUM_E = 0x00000044;
private const int PRODUCT_PROFESSIONAL_E = 0x00000045;
private const int PRODUCT_ENTERPRISE_E = 0x00000046;
private const int PRODUCT_ULTIMATE_E = 0x00000047;
#endregion PRODUCT
#region VERSIONS
private const int VER_NT_WORKSTATION = 1;
private const int VER_NT_DOMAIN_CONTROLLER = 2;
private const int VER_NT_SERVER = 3;
private const int VER_SUITE_SMALLBUSINESS = 1;
private const int VER_SUITE_ENTERPRISE = 2;
private const int VER_SUITE_TERMINAL = 16;
private const int VER_SUITE_DATACENTER = 128;
private const int VER_SUITE_SINGLEUSERTS = 256;
private const int VER_SUITE_PERSONAL = 512;
private const int VER_SUITE_BLADE = 1024;
#endregion VERSIONS
#endregion PINVOKE
#region SERVICE PACK
static public string ServicePack
{
get
{
string servicePack = String.Empty;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
if (GetVersionEx(ref osVersionInfo))
{
servicePack = osVersionInfo.szCSDVersion;
}
return servicePack;
}
}
#endregion SERVICE PACK
#region VERSION
#region BUILD
static public int BuildVersion
{
get
{
return Environment.OSVersion.Version.Build;
}
}
#endregion BUILD
#region FULL
#region STRING
static public string VersionString
{
get
{
return Environment.OSVersion.Version.ToString();
}
}
#endregion STRING
#region VERSION
static public Version Version
{
get
{
return Environment.OSVersion.Version;
}
}
#endregion VERSION
#endregion FULL
#region MAJOR
static public int MajorVersion
{
get
{
return Environment.OSVersion.Version.Major;
}
}
#endregion MAJOR
#region MINOR
static public int MinorVersion
{
get
{
return Environment.OSVersion.Version.Minor;
}
}
#endregion MINOR
#region REVISION
static public int RevisionVersion
{
get
{
return Environment.OSVersion.Version.Revision;
}
}
#endregion REVISION
#endregion VERSION
#region 64 BIT OS DETECTION
private static IsWow64ProcessDelegate GetIsWow64ProcessDelegate()
{
IntPtr handle = LoadLibrary("kernel32");
if (handle != IntPtr.Zero)
{
IntPtr fnPtr = GetProcAddress(handle, "IsWow64Process");
if (fnPtr != IntPtr.Zero)
{
return (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer((IntPtr)fnPtr, typeof(IsWow64ProcessDelegate));
}
}
return null;
}
private static bool Is32BitProcessOn64BitProcessor()
{
IsWow64ProcessDelegate fnDelegate = GetIsWow64ProcessDelegate();
if (fnDelegate == null)
{
return false;
}
bool isWow64;
bool retVal = fnDelegate.Invoke(Process.GetCurrentProcess().Handle, out isWow64);
if (retVal == false)
{
return false;
}
return isWow64;
}
#endregion 64 BIT OS DETECTION
}
}
...this update does of course assume access to the registry. If access is denied, then it will still perform as originally intended - meaning Windows 8.1 will be reported as Windows 8. Without the registry or a Windows 8.1 manifested application than it's impossible to know the exact version.
Great work Johnny J - hope you approve of the update!
Scott Vickery
|
|
|
|
|
Late, I know, but thanks a lot Scott! You registry workaround seems to work perfectly for Windows 8.1
When it comes to Windows 10, though, I can't get the right version out no matter what (without specifically manifesting it in the app manifest, but I would like it to work even without that). Will try to solve the puzzle anyway, but I wonder why MS has to make it so hard for developers. Why the HE** can't you just query Environment.OSVersion and get the RIGHT OS version?
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|