From: Eliyas Yakub [eliyasy@microsoft.com] Sent: Wednesday, August 04, 1999 5:45 PM To: 'Himanshu Chatterjee' Cc: 'ntdev@atria.com' Subject: RE: [ntdev] How to Query Plug & play devices You can get information about all kinds of devices (real\virtual\logical) currently present in the system using CM APIs. The function code given here basically walks the devnode tree and prints the device description of all the devices. I just modified DriverNameToDeviceDesc functions used in USBVIEW sample of DDK (ddk\src\wdm\usbview\devnode.c) to demonstrate this functionality. #include #include #include #include #include CHAR buf[512]; // XXXXX How big does this have to be? Dynamically size it? VOID PrintDeviceDesc () { DEVINST devInst; DEVINST devInstNext; CONFIGRET cr; ULONG walkDone = 0; ULONG len; // Get Root DevNode // cr = CM_Locate_DevNode(&devInst, NULL, 0); if (cr != CR_SUCCESS) { return; } // Do a depth first search for the DevNode with a matching // DriverName value // while (!walkDone) { // Get the DriverName value // len = sizeof(buf); cr = CM_Get_DevNode_Registry_Property(devInst, CM_DRP_DRIVER, NULL, buf, &len, 0); // If the DriverName value matches, return the DeviceDescription // if (cr == CR_SUCCESS ) { len = sizeof(buf); cr = CM_Get_DevNode_Registry_Property(devInst, CM_DRP_DEVICEDESC, NULL, buf, &len, 0); if (cr == CR_SUCCESS) { printf("%s\n", buf); } else { return ; } } // This DevNode didn't match, go down a level to the first child. // cr = CM_Get_Child(&devInstNext, devInst, 0); if (cr == CR_SUCCESS) { devInst = devInstNext; continue; } // Can't go down any further, go across to the next sibling. If // there are no more siblings, go back up until there is a sibling. // If we can't go up any further, we're back at the root and we're // done. // for (;;) { cr = CM_Get_Sibling(&devInstNext, devInst, 0); if (cr == CR_SUCCESS) { devInst = devInstNext; break; } cr = CM_Get_Parent(&devInstNext, devInst, 0); if (cr == CR_SUCCESS) { devInst = devInstNext; } else { walkDone = 1; break; } } } return ; } -----Original Message----- From: Himanshu Chatterjee [mailto:CHIMANSHU@novell.com] Sent: Tuesday, August 03, 1999 10:06 PM To: ntdev@atria.com Subject: [ntdev] How to Query Plug & play devices Hello, Can anyone advice me how to get information about all the Plug and Play devices in the system ? Is there any other means other than registry. Registy contains information of all the devices which were once installed but currently are not used. So is there any fool proof way of doing this ? Thanks Himanshu - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ To unsubscribe, send email to ntdev-request@atria.com with body UNSUBSCRIBE (the subject is ignored). ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ To unsubscribe, send email to ntdev-request@atria.com with body UNSUBSCRIBE (the subject is ignored). ]