Refactor system info queries to use WMI, remove User32 dependency - #126
Merged
Conversation
Replaced User32-based system metric queries with WMI (CimSession) for boot type and display count. Updated ComputerSystemHelpers and VideoHelpers to use WMI queries. Removed SystemMetricsHelper and the Vanara.PInvoke.User32 package, adding Vanara.PInvoke.Kernel32 instead. Improved consistency in region naming.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors Windows system-information collection to rely on WMI via CimSession instead of User32 P/Invoke, removing the dedicated SystemMetricsHelper and updating helpers to query boot type and display-count through WMI.
Changes:
- Replace
User32-based system metrics with WMI queries for boot type and monitor count. - Remove
SystemMetricsHelperand swap the Vanara dependency fromVanara.PInvoke.User32toVanara.PInvoke.Kernel32. - Minor consistency updates (e.g., region naming).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| TimVer/TimVer.csproj | Removes Vanara.PInvoke.User32 and adds Vanara.PInvoke.Kernel32 to align dependencies with the refactor. |
| TimVer/Helpers/VideoHelpers.cs | Switches display-count reporting to a WMI-based query and introduces a new GetDisplayCount() helper. |
| TimVer/Helpers/SystemMetricsHelper.cs | Deletes the User32-backed helper previously used for display count and clean boot detection. |
| TimVer/Helpers/ComputerSystemHelpers.cs | Replaces clean-boot metric usage with a WMI BootupState query to determine boot type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+168
to
+178
| using CimSession cimSession = CimSession.Create(null); | ||
| string? bootupState = cimSession.QueryInstances(_scope, _dialect, "SELECT BootupState From Win32_ComputerSystem") | ||
| .FirstOrDefault()?.CimInstanceProperties["BootupState"].Value.ToString(); | ||
|
|
||
| return bootupState switch | ||
| { | ||
| "Normal boot" => GetStringResource("HardwareInfo_LastBootNormal"), | ||
| "Fail-safe boot" => GetStringResource("HardwareInfo_LastBootSafe"), | ||
| "Fail-safe with network boot" => GetStringResource("HardwareInfo_LastBootSafeNetwork"), | ||
| _ => string.Empty, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaced User32-based system metric queries with WMI (CimSession) for boot type and display count. Updated ComputerSystemHelpers and VideoHelpers to use WMI queries. Removed SystemMetricsHelper and the Vanara.PInvoke.User32 package, adding Vanara.PInvoke.Kernel32 instead. Improved consistency in region naming.