Skip to content

Commit

Permalink
HwInfo/SetupApi: enumerate only started devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixaill committed May 13, 2021
1 parent c85733a commit cb39af3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Mixaill.HwInfo.SetupApi/Defines/DeviceNodeStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2021, Mikhail Paulyshka
// SPDX-License-Identifier: MIT

namespace Mixaill.HwInfo.SetupApi.Defines
{
enum DeviceNodeStatus : uint
{
Started = 0x00000008
}
}
11 changes: 10 additions & 1 deletion Mixaill.HwInfo.SetupApi/DeviceInfoSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ private unsafe void Initialize()
data.cbSize = (uint)sizeof(SP_DEVINFO_DATA);
while (PInvoke.SetupDiEnumDeviceInfo((void*)_handle.Value, idx, out data))
{
Devices.Add(DeviceInfoFactory.Create(this, data));
uint status = 0;
uint problem_number = 0;
if(PInvoke.CM_Get_DevNode_Status(out status, out problem_number, data.DevInst, 0) == CONFIGRET.CR_SUCCESS)
{
if ((status & (uint)DeviceNodeStatus.Started) == (uint)DeviceNodeStatus.Started)
{
Devices.Add(DeviceInfoFactory.Create(this, data));
}
}

idx++;
}
}
Expand Down
1 change: 1 addition & 0 deletions Mixaill.HwInfo.SetupApi/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
INVALID_HANDLE_VALUE

// DevInst/Functions
CM_Get_DevNode_Status
CM_Get_First_Log_Conf
CM_Get_Next_Res_Des
CM_Get_Res_Des_Data
Expand Down

0 comments on commit cb39af3

Please sign in to comment.