diff options
Diffstat (limited to 'crates/windows-kernel-rs/src/version.rs')
| -rw-r--r-- | crates/windows-kernel-rs/src/version.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/crates/windows-kernel-rs/src/version.rs b/crates/windows-kernel-rs/src/version.rs new file mode 100644 index 0000000..3f46a87 --- /dev/null +++ b/crates/windows-kernel-rs/src/version.rs @@ -0,0 +1,35 @@ +//! This module provides utilities to query information about the version of +//! Microsoft Windows. + +use windows_kernel_sys::{base::RTL_OSVERSIONINFOW, ntoskrnl::RtlGetVersion}; + +use crate::error::{Error, IntoResult}; + +/// Represents version information for Microsoft Windows. +pub struct VersionInfo { + version_info: RTL_OSVERSIONINFOW, +} + +impl VersionInfo { + /// Uses [`RtlGetVersion`] to query the version info for Microsoft Windows. + pub fn query() -> Result<Self, Error> { + let mut version_info: RTL_OSVERSIONINFOW = unsafe { core::mem::zeroed() }; + + version_info.dwOSVersionInfoSize = core::mem::size_of::<RTL_OSVERSIONINFOW>() as u32; + + unsafe { RtlGetVersion(&mut version_info) }.into_result()?; + + Ok(Self { + version_info, + }) + } + + /// Retrieves the major version of Microsoft Windows. + pub fn major(&self) -> u32 { self.version_info.dwMajorVersion } + + /// Retrieves the minor version of Microsoft Windows. + pub fn minor(&self) -> u32 { self.version_info.dwMinorVersion } + + /// Retrieves the build number of Microsoft Windows. + pub fn build_number(&self) -> u32 { self.version_info.dwBuildNumber } +} |