#os-version #windows #winapi #version #api-version #os

winver

winver is a tiny crate to detect real OS version on Windows depending on windows crate only. There are several ways to get Windows OS version and each of them has its pitfall. This crate provides API to get the version more easily and safely avoiding the pitfalls.

3 releases (1 stable)

1.0.0 Jul 30, 2023
0.1.1 Jul 28, 2023
0.1.0 Jul 28, 2023

#94 in Windows APIs

Download history 2364/week @ 2024-06-17 1582/week @ 2024-06-24 1493/week @ 2024-07-01 2012/week @ 2024-07-08 1994/week @ 2024-07-15 2004/week @ 2024-07-22 1909/week @ 2024-07-29 1845/week @ 2024-08-05 1561/week @ 2024-08-12 1610/week @ 2024-08-19 2114/week @ 2024-08-26 1517/week @ 2024-09-02 1541/week @ 2024-09-09 2424/week @ 2024-09-16 2339/week @ 2024-09-23 3525/week @ 2024-09-30

9,936 downloads per month
Used in 3 crates

MIT license

27KB
443 lines

winver crate

CI crate docs

winver is a tiny Rust crate to detect real Windows OS version depending on windows crate only.

use winver::WindowsVersion;

let version = WindowsVersion::detect().unwrap();
if version >= WindowsVersion::new(10, 0, 15063) {
    println!("OS version is 10.0.15063 or later: {}", version);
}

There are several ways to get Windows OS version and each of them has its pitfall. This crate provides API to get the version more easily and safely avoiding the pitfalls.

The above WindowsVersion::detect function works as follows:

  1. Try to get OS version from RtlGetVersion function in ntdll.dll. However it is a kernel mode function and ntdll.dll does not always exist.
  2. Try to get OS version from WMI's Win32_OperatingSystem provider via WQL. WMI may not be available due to the process security level setting.
  3. Try to get OS version from a file version information of kernel32.dll. However the version information in file might be slightly different from the actual OS version.
  4. Try to get OS version from GetVersionExW function as fallback. This is an official way to get OS version but it lies if the program is running in compatibility mode and it requires to embed compatibility manifest in your executable.
  5. Give up getting OS version and return None.

Each steps are implemented as isolated funcitons in WindowsVersion. For example, the step 1. is equivalent to WindowsVersion::from_ntdll_dll.

This logic was implemented referring to the implementation of Python's sys.getwindowsversion and platform.win32_ver.

See the API documentation for more details.

Installation

Add the following lines to your project's Cargo.toml. Note that winver crate is available only on Windows.

[target."cfg(windows)".dependencies]
winver = "1"

Minimum supported Rust version is 1.65.0 for using let-else statement.

License

Distributed under the MIT license.

Dependencies

~129MB
~2M SLoC