Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

OSVERSIONINFO (Structures)
 
.
Summary
The OSVERSIONINFOEX structure contains operating system version information. The information includes major and minor version numbers, a build number, a platform identifier, and information about product suites and the latest Service Pack installed on the system.
Summary
Contains OS version information.

C# Definition:

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]  
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 UInt16 wServicePackMajor;  
   public UInt16 wServicePackMinor;  
   public UInt16 wSuiteMask;
   public byte wProductType;  
   public byte wReserved;

}

C# Definitions:

// Use this when the unmanaged API expects the structure passed by-value, or
// or if you want to pass it by-reference as a pointer to a structure
struct OSVERSIONINFO {
    public uint dwOSVersionInfoSize;
    public uint dwMajorVersion;
    public uint dwMinorVersion;
    public uint dwBuildNumber;
    public uint dwPlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
    public string szCSDVersion;
    public Int16 wServicePackMajor;
    public Int16 wServicePackMinor;
    public Int16 wSuiteMask;
    public Byte wProductType;
    public Byte wReserved;
}

C# Definition (with Enums):

  [StructLayout(LayoutKind.Sequential)]
  struct OSVERSIONINFOEX
  {
    public uint dwOSVersionInfoSize;
    public uint dwMajorVersion;
    public uint dwMinorVersion;
    public uint dwBuildNumber;
    public uint dwPlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string szCSDVersion;
    public ushort wServicePackMajor;
    public ushort wServicePackMinor;
    public SuiteMask wSuiteMask;
    public ProductType wProductType;
    public byte wReserved;
  }
// Use this when you want to pass it by-value even though the unmanaged API
// expects a pointer to a structure.  Being a class adds an extra level of indirection.
[StructLayout(LayoutKind.Sequential)]  
class OSVERSIONINFO
{
    public uint dwOSVersionInfoSize;
    public uint dwMajorVersion;
    public uint dwMinorVersion;
    public uint dwBuildNumber;
    public uint dwPlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
    public string szCSDVersion;
    public Int16 wServicePackMajor;
    public Int16 wServicePackMinor;
    public Int16 wSuiteMask;
    public Byte wProductType;
    public Byte wReserved;
}

  enum ProductType : byte
  {
    VER_NT_DOMAIN_CONTROLLER = 0x0000002,
    VER_NT_SERVER = 0x0000003,
    VER_NT_WORKSTATION = 0x0000001,
  }

VB Definitions:

' Use this when the unmanaged API expects the structure passed by-value, or
' or if you want to pass it by-reference as a pointer to a structure
' If you plan to call "GetVersionExW" Use CharSet.Unicode
' If you are calling "GetVersionExA", Use CharSet.Ansi
  <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
  Structure OSVERSIONINFO
    Public dwOSVersionInfoSize As Int32
    Public dwMajorVersion As Int32
    Public dwMinorVersion As Int32
    Public dwBuildNumber As Int32
    Public dwPlatformId As Int32
    <VBFixedString(128), MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public szCSDVersion As String
    Public wServicePackMajor As Int16
    Public wServicePackMinor As Int16
    Public wSuiteMask As Int16
    Public wProductType As Byte
    Public wReserved As Byte
End Structure

  [Flags]
  enum SuiteMask : ushort
  {
    VER_SUITE_BACKOFFICE = 0x00000004,
    VER_SUITE_BLADE = 0x00000400,
    VER_SUITE_COMPUTE_SERVER = 0x00004000,
    VER_SUITE_DATACENTER = 0x00000080,
    VER_SUITE_ENTERPRISE = 0x00000002,
    VER_SUITE_EMBEDDEDNT = 0x00000040,
    VER_SUITE_PERSONAL = 0x00000200,
    VER_SUITE_SINGLEUSERTS = 0x00000100,
    VER_SUITE_SMALLBUSINESS = 0x00000001,
    VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020,
    VER_SUITE_STORAGE_SERVER = 0x00002000,
    VER_SUITE_TERMINAL = 0x00000010,
    VER_SUITE_WH_SERVER = 0x00008000,
  }
' Use this when you want to pass it by-value even though the unmanaged API
' expects a pointer to a structure.  Being a class adds an extra level of indirection.
<StructLayout(LayoutKind.Sequential)> _
Class OSVERSIONINFO
    Public dwOSVersionInfoSize As Int32
    Public dwMajorVersion As Int32
    Public dwMinorVersion As Int32
    Public dwBuildNumber As Int32
    Public dwPlatformId As Int32
    <VBFixedString(128), MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public szCSDVersion As String
    Public wServicePackMajor As Int16
    Public wServicePackMinor As Int16
    Public wSuiteMask As Int16
    Public wProductType As Byte
    Public wReserved As Byte
End Class

VB Definition:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _

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 UInt16
   Public wServicePackMinor As UInt16
   Public wSuiteMask As UInt16
   Public wProductType As Byte
   Public wReserved As Byte

End Structure 'OSVERSIONINFOEX

User-Defined Field Types:

None.

Notes:

Use the overloaded API call GetVersionEx().

Documentation
Documentation

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • alternate definitions?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions