Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get Information whether Device is attached or not

2 views
Skip to first unread message

Kerem Gümrükcü

unread,
Jul 21, 2008, 3:40:19 PM7/21/08
to
Hi,

i get with SetupDiGetClassDevs and DIGCF_ALLCLASSES all devices
on my system, including the ones that are not attached to my system. This
is exactly what i want, but how can i see which device in my list ist
attached to the system and which one is not, Is there some flag somewhere
in a data structure i can get by calling something,...?

TIA,...

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.codeplex.com/restarts
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."

Pavel A.

unread,
Jul 21, 2008, 8:10:10 PM7/21/08
to
Use the DIGCF_PRESENT flag.

--PA

"Kerem Gümrükcü" <kare...@hotmail.com> wrote in message
news:OEt#Dn26IH...@TK2MSFTNGP02.phx.gbl...

Kerem Gümrükcü

unread,
Jul 22, 2008, 1:39:20 AM7/22/08
to
Hi Pavel,

i either use DIGCF_PRESENT or the DIGCF_ALLCLASSES, depending
on what i need, but mostly i have to see ALL devices on my system, so the
point is to select between devices that are attached physically to my system
and those who are not,...there must be some flag somewhere or a SetupDi*
function that can do this for me,...

Wilhelm Noeker

unread,
Jul 22, 2008, 3:25:48 AM7/22/08
to
Kerem Gümrükcü schrieb:

> i either use DIGCF_PRESENT or the DIGCF_ALLCLASSES, depending
> on what i need, but mostly i have to see ALL devices on my system, so the
> point is to select between devices that are attached physically to my
> system
> and those who are not,...there must be some flag somewhere or a SetupDi*
> function that can do this for me,...

Here's what I do, using the devInfo returned by SetupDiEnumDeviceInfo():

if( CM_Get_DevNode_Status( &lStatus, &lProblem, devInfo.DevInst, 0 ) !=
CR_SUCCESS )
printf( "device is currently not attached\n" );
else
{
if( lProblem == 0 )
printf( "device is running\n" );
else if( lProblem == CM_PROB_DISABLED )
printf( "device has been disabled\n" );
else
printf( "device has a problem, code %d\n", lProblem );
}

Stefan Kuhr

unread,
Jul 22, 2008, 4:55:21 AM7/22/08
to
Kerem,

Kerem Gümrükcü wrote:
> Hi Pavel,
>
> i either use DIGCF_PRESENT or the DIGCF_ALLCLASSES, depending
> on what i need, but mostly i have to see ALL devices on my system, so the
> point is to select between devices that are attached physically to my
> system
> and those who are not,...there must be some flag somewhere or a SetupDi*
> function that can do this for me,...
>
> Regards
>
> Kerem
>

In addition to what Wilhelm noeker wrote: You might want to do a
CM_Get_DevNode_Status/CM_Get_DevNode_Status_Ex on the device node and
examine the status for the device that is returned. If the flag
DN_NO_SHOW_IN_DM is set, you can leave out that device.

--
S

DeStefan

unread,
Jul 22, 2008, 5:59:01 AM7/22/08
to
Kerem,
Well IMHO you give the easiest solution for your problem aready yourself:

>> i either use DIGCF_PRESENT or the DIGCF_ALLCLASSES, depending
>> on what i need, but mostly i have to see ALL devices on my system, so the
>> point is to select between devices that are attached physically to my
>> system
>> and those who are not
As you wrote you just need to compare the return handles from DIGCF_PRESENT
against those with DIGCF_ALLCLASSES then you know exactly the difference.
If the handle is in the list with allclasses, but not in the list of present
devices, you can display the device and mark it as "not present".
Be also aware of the fact that a device may be present, but disabled. in
latter case you will get the device as present, but it will not work. to be
really sure, if it is working, you need to create a handle to the driver. if
device is disabled, you get an invalid handle.

Pavel A.

unread,
Jul 22, 2008, 6:43:17 AM7/22/08
to
Kerem Gümrükcü wrote:
> Hi Pavel,
>
> i either use DIGCF_PRESENT or the DIGCF_ALLCLASSES, depending
> on what i need, but mostly i have to see ALL devices on my system, so the
> point is to select between devices that are attached physically to my
> system
> and those who are not,...there must be some flag somewhere or a SetupDi*
> function that can do this for me,...
>

Hi Kerem,

Use DIGCF_PRESENT to select _only_ devices that are currently attached.
This and DIGCF_ALLCLASSES are independent.

However - as Wilhelm Noeker wrote - attached devices can be either
working or having some problem (code 10, code 12, etc).
This you can see with CM_Get_DevNode_Status().

Regards,
--PA

Unknown

unread,
Aug 1, 2008, 1:02:01 PM8/1/08
to
Pavel is correct, you can use BOTH flags at the same time in a call to
SetupDiGetClassDevs(...): Use the binary-OR operator to combine the flags
like so: (DIGCF_PRESENT | DIGCF_ALLCLASSES). Using the DIGCF_PRESENT flag is
slightly more efficient and is likely to be even more efficient in future
versions of Windows.

If you absolutly need to know about non-present devices (not many people
do), then CM_Get_DevNode_Status() is your best bet for distinguishing between
present and non-present.

Also, if you know the specific Interface class(es) of the devices you're
interested in, (DIGCF_DEVICEINTERFACE) the call will be much faster if you
give it each interface class one by one.

Future versions of Windows may also have significant speedups if you provide
a specific setup Class GUID to the call.

Thanks,
-=Travis.Martin

0 new messages