Struct winver::WindowsVersion
source · pub struct WindowsVersion {
pub major: u32,
pub minor: u32,
pub build: u32,
}
Expand description
Windows OS version.
This type implements Eq
and Ord
so you can easily compare two versions.
assert!(WindowsVersion::new(10, 0, 1000) < WindowsVersion::new(10, 0, 2000));
This type provides four methods to detect the OS version.
Fields§
§major: u32
Major version of Windows OS.
minor: u32
Minor version of Windows OS.
build: u32
Build number of Windows OS.
Implementations§
source§impl WindowsVersion
impl WindowsVersion
sourcepub fn from_ntdll_dll() -> Result<Self, Error>
pub fn from_ntdll_dll() -> Result<Self, Error>
Detect the OS version of current Windows system using RtlGetVersion
function in ntdll.dll
DLL.
The obtained version is accurate. And this method is faster than WindowsVersion::from_wmi_os_provider
.
However ntdll.dll
does not always exist in your system and RtlGetVersion
is a kernel-mode function.
This method loads ntdll.dll
dynamically and tries to call RtlGetVersion
function in it. When the dynamic
call fails, this method returns an error.
sourcepub fn from_wmi_os_provider() -> Result<Self, Error>
pub fn from_wmi_os_provider() -> Result<Self, Error>
Detect the OS version of current Windows system using WMI’s Win32_OperatingSystem
provider
via WQL.
The obtained version is accurate. However WMI may not be available due to the process security level setting. When it is not possible to access the provider, this method returns an error.
sourcepub fn from_kernel32_dll() -> Result<Self, Error>
pub fn from_kernel32_dll() -> Result<Self, Error>
Detect the OS version of current Windows system from kernel32.dll
file’s version information.
The version actually represents the OS version where the kernel32.dll
file was built. The build number may be
slightly different from the actual OS version. This method should be used as fallback of other methods.
This method was implemented referring to Python’s sys.getwindowsversion
implementation.
sourcepub fn from_get_version_ex() -> Result<Self, Error>
pub fn from_get_version_ex() -> Result<Self, Error>
Detect the OS version of current Windows system using GetVersionEx
Win32 API.
You need to embed a compatibility manifest into your executable. Otherwise, this method always returns version 6.2 (Windows 8) even if you’re on Windows 10 or later. So this method should be used as fallback of other methods.
This behavior is a limitation of the GetVersionEx
function. Please read
the Remarks section of VerifyVersionInfo
document.
sourcepub fn detect() -> Option<Self>
pub fn detect() -> Option<Self>
Return the OS version of the current Windows system. This method tries to get the version with the following steps.
When no version could not be detected on all steps, this method returns None
.
- Try to detect the OS version with
WindowsVersion::from_ntdll_dll
- Try to detect the OS version with
WindowsVersion::from_wmi_os_provider
- Try to detect the OS version with
WindowsVersion::from_kernel32_dll
- Try to detect the OS version with
WindowsVersion::from_get_version_ex
Trait Implementations§
source§impl Clone for WindowsVersion
impl Clone for WindowsVersion
source§fn clone(&self) -> WindowsVersion
fn clone(&self) -> WindowsVersion
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for WindowsVersion
impl Debug for WindowsVersion
source§impl Display for WindowsVersion
impl Display for WindowsVersion
source§impl Hash for WindowsVersion
impl Hash for WindowsVersion
source§impl Ord for WindowsVersion
impl Ord for WindowsVersion
source§impl PartialEq<WindowsVersion> for WindowsVersion
impl PartialEq<WindowsVersion> for WindowsVersion
source§fn eq(&self, other: &WindowsVersion) -> bool
fn eq(&self, other: &WindowsVersion) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<WindowsVersion> for WindowsVersion
impl PartialOrd<WindowsVersion> for WindowsVersion
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more