diff --git a/PInvoke/NtDll/Wdm.cs b/PInvoke/NtDll/Wdm.cs index 41413a38..a420cee9 100644 --- a/PInvoke/NtDll/Wdm.cs +++ b/PInvoke/NtDll/Wdm.cs @@ -2397,6 +2397,35 @@ public static partial class NtDll // KeyInformation, uint Length, ref uint ResultLength); public static extern NTStatus NtQueryKey(HKEY KeyHandle, KEY_INFORMATION_CLASS KeyInformationClass, [Out] SafeHGlobalHandle KeyInformation, uint Length, out uint ResultLength); + /// Gets version information about the currently running operating system. + /// + /// Pointer to either a RTL_OSVERSIONINFOW structure or a RTL_OSVERSIONINFOEXW structure that contains the version + /// information about the currently running operating system. A caller specifies which input structure is used by setting the + /// dwOSVersionInfoSize member of the structure to the size in bytes of the structure that is used. + /// + /// Returns STATUS_SUCCESS. + /// + /// + /// RtlGetVersion is the equivalent of the GetVersionEx function in the Windows SDK. See the example in the Windows SDK + /// that shows how to get the system version. + /// + /// + /// When using RtlGetVersion to determine whether a particular version of the operating system is running, a caller should check + /// for version numbers that are greater than or equal to the required version number. This ensures that a version test succeeds for + /// later versions of Windows. + /// + /// + /// Because operating system features can be added in a redistributable DLL, checking only the major and minor version numbers is not the + /// most reliable way to verify the presence of a specific system feature. A driver should use RtlVerifyVersionInfo to test for + /// the presence of a specific system feature. + /// + /// + // https://learn.microsoft.com/en-us/windows/win32/devnotes/rtlgetversion + // NTSTATUS RtlGetVersion( _Out_ PRTL_OSVERSIONINFOW lpVersionInformation ); + [PInvokeData("Ntddk.h")] + [DllImport(Lib.NtDll, SetLastError = false, ExactSpelling = true)] + public static extern NTStatus RtlGetVersion(out OSVERSIONINFOW lpVersionInformation); + /// /// /// A driver sets an IRP's I/O status block to indicate the final status of an I/O request, before calling IoCompleteRequest for the IRP. @@ -2630,6 +2659,198 @@ public static partial class NtDll /// public StrPtrUni Name; } + + /// + /// + /// Contains operating system version information. The information includes major and minor version numbers, a build number, a platform + /// identifier, and descriptive text about the operating system. This structure is used with the GetVersionEx function. + /// + /// To obtain additional version information, use the OSVERSIONINFOEX structure with GetVersionEx instead. + /// + /// + /// + /// Relying on version information is not the best way to test for a feature. Instead, refer to the documentation for the feature of + /// interest. For more information on common techniques for feature detection, see Operating System Version. + /// + /// + /// If you must require a particular operating system, be sure to use it as a minimum supported version, rather than design the test for + /// the one operating system. This way, your detection code will continue to work on future versions of Windows. + /// + /// + /// The following table summarizes the values returned by supported versions of Windows. Use the information in the column labeled + /// "Other" to distinguish between operating systems with identical version numbers. + /// + /// + /// + /// Operating system + /// Version number + /// dwMajorVersion + /// dwMinorVersion + /// Other + /// + /// + /// Windows 10 + /// 10.0* + /// 10 + /// 0 + /// OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION + /// + /// + /// Windows Server 2016 + /// 10.0* + /// 10 + /// 0 + /// OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION + /// + /// + /// Windows 8.1 + /// 6.3* + /// 6 + /// 3 + /// OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION + /// + /// + /// Windows Server 2012 R2 + /// 6.3* + /// 6 + /// 3 + /// OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION + /// + /// + /// Windows 8 + /// 6.2 + /// 6 + /// 2 + /// OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION + /// + /// + /// Windows Server 2012 + /// 6.2 + /// 6 + /// 2 + /// OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION + /// + /// + /// Windows 7 + /// 6.1 + /// 6 + /// 1 + /// OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION + /// + /// + /// Windows Server 2008 R2 + /// 6.1 + /// 6 + /// 1 + /// OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION + /// + /// + /// Windows Server 2008 + /// 6.0 + /// 6 + /// 0 + /// OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION + /// + /// + /// Windows Vista + /// 6.0 + /// 6 + /// 0 + /// OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION + /// + /// + /// Windows Server 2003 R2 + /// 5.2 + /// 5 + /// 2 + /// GetSystemMetrics(SM_SERVERR2) != 0 + /// + /// + /// Windows Server 2003 + /// 5.2 + /// 5 + /// 2 + /// GetSystemMetrics(SM_SERVERR2) == 0 + /// + /// + /// Windows XP + /// 5.1 + /// 5 + /// 1 + /// Not applicable + /// + /// + /// Windows 2000 + /// 5.0 + /// 5 + /// 0 + /// Not applicable + /// + /// + /// + /// * For applications that have been manifested for Windows 8.1 or Windows 10. Applications not manifested for Windows 8.1 or + /// Windows 10 will return the Windows 8 OS version value (6.2). To manifest your applications for Windows 8.1 or Windows 10, refer + /// to Targeting your application for Windows. + /// + /// + /// + ///  + /// Examples + /// For an example, see Getting the System Version. + /// + /// Note + /// + /// The winnt.h header defines OSVERSIONINFO as an alias which automatically selects the ANSI or Unicode version of this function based + /// on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not + /// encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for + /// Function Prototypes. + /// + /// + /// + // https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfow typedef struct _OSVERSIONINFOW { DWORD + // dwOSVersionInfoSize; DWORD dwMajorVersion; DWORD dwMinorVersion; DWORD dwBuildNumber; DWORD dwPlatformId; WCHAR szCSDVersion[128]; } + // OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW; + [PInvokeData("winnt.h", MSDNShortId = "NS:winnt._OSVERSIONINFOW")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct OSVERSIONINFOW + { + /// The size of this data structure, in bytes. Set this member to . + public uint dwOSVersionInfoSize; + + /// The major version number of the operating system. For more information, see Remarks. + public uint dwMajorVersion; + + /// The minor version number of the operating system. For more information, see Remarks. + public uint dwMinorVersion; + + /// The build number of the operating system. + public uint dwBuildNumber; + + /// + /// The operating system platform. This member can be the following value. + /// + /// + /// Value + /// Meaning + /// + /// + /// VER_PLATFORM_WIN32_NT 2 + /// + /// The operating system is Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, or Windows 2000. + /// + /// + /// + /// + public uint dwPlatformId; + + /// + /// A null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack installed on the system. If no Service + /// Pack has been installed, the string is empty. + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] + public string szCSDVersion; + } + /* ACCESS_STATE structure ACL structure