Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Commit 7bfc73d

Browse files
committed
Merge pull request #438 from vatsanm/ntdll-versionapis
2 parents 559d605 + 27d4f96 commit 7bfc73d

9 files changed

+522
-1
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright (c) All contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace PInvoke
5+
{
6+
using System.Runtime.InteropServices;
7+
8+
/// <summary>
9+
/// Contains the <see cref="OSVERSIONINFOEX"/> nested type.
10+
/// </summary>
11+
public static partial class Kernel32
12+
{
13+
/// <summary>
14+
/// The RTL_OSVERSIONINFOEXW structure contains operating system version information.
15+
/// </summary>
16+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
17+
public unsafe partial struct OSVERSIONINFOEX
18+
{
19+
/// <summary>
20+
/// The size, in bytes, of an RTL_OSVERSIONINFOEXW structure.
21+
/// This member must be set before the structure is used with RtlGetVersion.
22+
/// </summary>
23+
public int dwOSVersionInfoSize;
24+
25+
/// <summary>
26+
/// The major version number of the operating system. For example, for Windows 2000, the major version number is five.
27+
/// </summary>
28+
public int dwMajorVersion;
29+
30+
/// <summary>
31+
/// The minor version number of the operating system. For example, for Windows 2000, the minor version number is zero
32+
/// </summary>
33+
public int dwMinorVersion;
34+
35+
/// <summary>
36+
/// The build number of the operating system.
37+
/// </summary>
38+
public int dwBuildNumber;
39+
40+
/// <summary>
41+
/// The operating system platform. For Win32 on NT-based operating systems, RtlGetVersion returns the value
42+
/// VER_PLATFORM_WIN32_NT.
43+
/// </summary>
44+
public int dwPlatformId;
45+
46+
/// <summary>
47+
/// The service-pack version string. This member contains a null-terminated string, such as "Service Pack 3", which
48+
/// indicates the latest service pack installed on the system. If no service pack is installed, RtlGetVersion might not
49+
/// initialize this string. Initialize szCSDVersion to zero (empty string) before the call to RtlGetVersion.
50+
/// </summary>
51+
public fixed char szCSDVersion[128];
52+
53+
/// <summary>
54+
/// The major version number of the latest service pack installed on the system. For example, for Service Pack 3,
55+
/// the major version number is three. If no service pack has been installed, the value is zero.
56+
/// </summary>
57+
public short wServicePackMajor;
58+
59+
/// <summary>
60+
/// The minor version number of the latest service pack installed on the system. For example, for Service Pack 3,
61+
/// the minor version number is zero.
62+
/// </summary>
63+
public short wServicePackMinor;
64+
65+
/// <summary>
66+
/// The product suites available on the system. This member is set to zero or to the bitwise OR of one or more of
67+
/// the <see cref="PRODUCT_SUITE"/> values.
68+
/// </summary>
69+
public PRODUCT_SUITE wSuiteMask;
70+
71+
/// <summary>
72+
/// The product type. This member contains additional information about the system.
73+
/// </summary>
74+
public OS_TYPE wProductType;
75+
76+
/// <summary>
77+
/// Reserved for future use.
78+
/// </summary>
79+
public byte wReserved;
80+
81+
/// <summary>
82+
/// Helper method to create <see cref="OSVERSIONINFOEX"/> with
83+
/// the right pre-initialization for <see cref="dwOSVersionInfoSize"/>
84+
/// </summary>
85+
/// <returns>A newly initialzed instance of <see cref="OSVERSIONINFOEX"/></returns>
86+
public static OSVERSIONINFOEX Create() => new OSVERSIONINFOEX
87+
{
88+
#if NETSTANDARD1_3_ORLATER || NETFX_CORE
89+
dwOSVersionInfoSize = Marshal.SizeOf<OSVERSIONINFOEX>()
90+
#else
91+
dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX))
92+
#endif
93+
};
94+
}
95+
}
96+
}

src/Kernel32/Kernel32+OS_TYPE.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) All contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace PInvoke
5+
{
6+
/// <summary>
7+
/// Contains the <see cref="OS_TYPE"/> nested type.
8+
/// </summary>
9+
public static partial class Kernel32
10+
{
11+
/// <summary>
12+
/// The product type enumeration
13+
/// </summary>
14+
public enum OS_TYPE : byte
15+
{
16+
VER_NT_WORKSTATION = 0x00000001,
17+
VER_NT_DOMAIN_CONTROLLER = 0x00000002,
18+
VER_NT_SERVER = 0x00000003
19+
}
20+
}
21+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright (c) All contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace PInvoke
5+
{
6+
using System;
7+
8+
/// <summary>
9+
/// Contains the <see cref="PRODUCT_SUITE"/> nested type
10+
/// </summary>
11+
public static partial class Kernel32
12+
{
13+
/// <summary>
14+
/// The product suites available on the system.
15+
/// </summary>
16+
[Flags]
17+
public enum PRODUCT_SUITE : short
18+
{
19+
/// <summary>
20+
/// Microsoft BackOffice components are installed.
21+
/// </summary>
22+
VER_SUITE_BACKOFFICE = 0x00000004,
23+
24+
/// <summary>
25+
/// Windows Server 2003, Web Edition is installed.
26+
/// </summary>
27+
VER_SUITE_BLADE = 0x00000400,
28+
29+
/// <summary>
30+
/// Windows Server 2003, Compute Cluster Edition is installed.
31+
/// </summary>
32+
VER_SUITE_COMPUTE_SERVER = 0x00004000,
33+
34+
/// <summary>
35+
/// Windows Server 2008 Datacenter, Windows Server 2003, Datacenter Edition, or Windows 2000 Datacenter Server is installed.
36+
/// </summary>
37+
VER_SUITE_DATACENTER = 0x00000080,
38+
39+
/// <summary>
40+
/// Windows Server 2008 Enterprise, Windows Server 2003, Enterprise Edition, or Windows 2000 Advanced Server is installed.
41+
/// </summary>
42+
VER_SUITE_ENTERPRISE = 0x00000002,
43+
44+
/// <summary>
45+
/// Windows XP Embedded is installed.
46+
/// </summary>
47+
VER_SUITE_EMBEDDEDNT = 0x00000040,
48+
49+
/// <summary>
50+
/// Windows Vista Home Premium, Windows Vista Home Basic, or Windows XP Home Edition is installed.
51+
/// </summary>
52+
VER_SUITE_PERSONAL = 0x00000200,
53+
54+
/// <summary>
55+
/// Remote Desktop is supported, but only one interactive session is supported.
56+
/// This value is set unless the system is running in application server mode.
57+
/// </summary>
58+
VER_SUITE_SINGLEUSERTS = 0x00000100,
59+
60+
/// <summary>
61+
/// Microsoft Small Business Server was once installed on the system, but may have been upgraded to another version of Windows.
62+
/// </summary>
63+
/// <remarks>
64+
/// You should not rely solely on the <see cref="VER_SUITE_SMALLBUSINESS"/> flag to determine whether Small Business Server is currently installed.
65+
/// Both this flag and the <see cref="VER_SUITE_SMALLBUSINESS_RESTRICTED"/> flag are set when this product suite is installed. If you upgrade this
66+
/// installation to Windows Server, Standard Edition, the <see cref="VER_SUITE_SMALLBUSINESS_RESTRICTED"/> flag is cleared, but the
67+
/// <see cref="VER_SUITE_SMALLBUSINESS"/> flag remains set, which, in this case, indicates that Small Business Server was previously installed on
68+
/// this system. If this installation is further upgraded to Windows Server, Enterprise Edition, the <see cref="VER_SUITE_SMALLBUSINESS"/> flag
69+
/// remains set.
70+
/// </remarks>
71+
VER_SUITE_SMALLBUSINESS = 0x00000001,
72+
73+
/// <summary>
74+
/// Microsoft Small Business Server is installed with the restrictive client license in force.
75+
/// For more information about this flag bit, see the remarks for <see cref="VER_SUITE_SMALLBUSINESS"/> flag.
76+
/// </summary>
77+
VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020,
78+
79+
/// <summary>
80+
/// Windows Storage Server 2003 R2 or Windows Storage Server 2003 is installed.
81+
/// </summary>
82+
VER_SUITE_STORAGE_SERVER = 0x00002000,
83+
84+
/// <summary>
85+
/// Terminal Services is installed. This value is always set. If <see cref="VER_SUITE_TERMINAL"/> is set but <see cref="VER_SUITE_SINGLEUSERTS"/> is not set,
86+
/// the operating system is running in application server mode.
87+
/// </summary>
88+
VER_SUITE_TERMINAL = 0x00000010,
89+
90+
/// <summary>
91+
/// Windows Home Server is installed.
92+
/// </summary>
93+
VER_SUITE_WH_SERVER = unchecked((short)0x00008000)
94+
}
95+
}
96+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) All contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace PInvoke
5+
{
6+
/// <summary>
7+
/// Contains the nested type <see cref="VER_CONDITION"/>
8+
/// </summary>
9+
public static partial class Kernel32
10+
{
11+
/// <summary>
12+
/// The operator to be used for the comparison. The <see cref="VerifyVersionInfo(OSVERSIONINFOEX*, VER_MASK, long)"/> function uses this operator to compare a specified
13+
/// attribute value to the corresponding value for the currently running system.
14+
/// </summary>
15+
/// <remarks>
16+
/// For all values of dwTypeBitMask other than VER_SUITENAME, this parameter can be one of the following values:
17+
/// - <see cref="VER_EQUAL"/>
18+
/// - <see cref="VER_GREATER"/>
19+
/// - <see cref="VER_GREATER_EQUAL"/>
20+
/// - <see cref="VER_LESS"/>
21+
/// - <see cref="VER_LESS_EQUAL"/>
22+
/// If dwTypeBitMask is VER_SUITENAME, this parameter can be one of the following values:
23+
/// - <see cref="VER_AND"/>
24+
/// - <see cref="VER_OR"/>
25+
/// </remarks>
26+
public enum VER_CONDITION : byte
27+
{
28+
/// <summary>
29+
/// The current value must be equal to the specified value.
30+
/// </summary>
31+
VER_EQUAL = 1,
32+
33+
/// <summary>
34+
/// The current value must be greater than the specified value.
35+
/// </summary>
36+
VER_GREATER = 2,
37+
38+
/// <summary>
39+
/// The current value must be greater than or equal to the specified value.
40+
/// </summary>
41+
VER_GREATER_EQUAL = 3,
42+
43+
/// <summary>
44+
/// The current value must be less than the specified value.
45+
/// </summary>
46+
VER_LESS = 4,
47+
48+
/// <summary>
49+
/// The current value must be less than or equal to the specified value.
50+
/// </summary>
51+
VER_LESS_EQUAL = 5,
52+
53+
/// <summary>
54+
/// All product suites specified in the wSuiteMask member must be present in the current system.
55+
/// </summary>
56+
VER_AND = 6,
57+
58+
/// <summary>
59+
/// At least one of the specified product suites must be present in the current system.
60+
/// </summary>
61+
VER_OR = 7
62+
}
63+
}
64+
}

src/Kernel32/Kernel32+VER_MASK.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) All contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace PInvoke
5+
{
6+
using System;
7+
8+
/// <summary>
9+
/// Contains the <see cref="VER_MASK"/> nested type.
10+
/// </summary>
11+
public static partial class Kernel32
12+
{
13+
/// <summary>
14+
/// A mask that indicates the member of the <see cref="OSVERSIONINFOEX"/> structure whose comparison operator is being set.
15+
/// This value corresponds to one of the bits specified in the dwTypeMask parameter for the <see cref="VerifyVersionInfo(OSVERSIONINFOEX*, VER_MASK, long)"/> function.
16+
/// </summary>
17+
[Flags]
18+
public enum VER_MASK : int
19+
{
20+
/// <summary>
21+
/// dwBuildNumber
22+
/// </summary>
23+
VER_BUILDNUMBER = 0x0000004,
24+
25+
/// <summary>
26+
/// dwBuildNumber
27+
/// </summary>
28+
VER_MAJORVERSION = 0x0000002,
29+
30+
/// <summary>
31+
/// dwMinorVersion
32+
/// </summary>
33+
VER_MINORVERSION = 0x0000001,
34+
35+
/// <summary>
36+
/// dwPlatformId
37+
/// </summary>
38+
VER_PLATFORMID = 0x0000008,
39+
40+
/// <summary>
41+
/// wProductType
42+
/// </summary>
43+
VER_PRODUCT_TYPE = 0x0000080,
44+
45+
/// <summary>
46+
/// wServicePackMajor
47+
/// </summary>
48+
VER_SERVICEPACKMAJOR = 0x0000020,
49+
50+
/// <summary>
51+
/// wServicePackMinor
52+
/// </summary>
53+
VER_SERVICEPACKMINOR = 0x0000010,
54+
55+
/// <summary>
56+
/// wSuiteMask
57+
/// </summary>
58+
VER_SUITENAME = 0x0000040
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)