Skip to content

Refactor system info queries to use WMI, remove User32 dependency - #126

Merged
Timthreetwelve merged 2 commits into
mainfrom
Replace-SystemMetricsHelper
Jul 14, 2026
Merged

Refactor system info queries to use WMI, remove User32 dependency#126
Timthreetwelve merged 2 commits into
mainfrom
Replace-SystemMetricsHelper

Conversation

@Timthreetwelve

Copy link
Copy Markdown
Owner

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.

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.
Copilot AI review requested due to automatic review settings July 14, 2026 01:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SystemMetricsHelper and swap the Vanara dependency from Vanara.PInvoke.User32 to Vanara.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 thread TimVer/Helpers/VideoHelpers.cs Outdated
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,
};
@Timthreetwelve
Timthreetwelve merged commit 19deb27 into main Jul 14, 2026
2 checks passed
@Timthreetwelve
Timthreetwelve deleted the Replace-SystemMetricsHelper branch July 14, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants