Crates.io | winver |
lib.rs | winver |
version | 1.0.0 |
source | src |
created_at | 2023-07-28 14:31:30.650304 |
updated_at | 2023-07-30 11:52:32.76281 |
description | 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. |
homepage | https://github.com/rhysd/winver#readme |
repository | https://github.com/rhysd/winver |
max_upload_size | |
id | 928562 |
size | 27,473 |
winver
cratewinver
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:
RtlGetVersion
function in ntdll.dll. However it is a kernel mode function and
ntdll.dll does not always exist.Win32_OperatingSystem
provider via WQL. WMI may not be available
due to the process security level setting.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.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.
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.
Distributed under the MIT license.