Windows USB device refresh in C\C++

Posted on 2009-05-22
Medium Priority
Last Modified: 2013-12-14
I am trying to find a way to programmatically re-enumerate the USB devices connected to the USB ports of a pc.  In windows XP, it is possible to open the Device Manager, right click on the PC name and select "Scan for Hardware Changes".  How can I execute this (or something similar but specific to the USB bus) from a C\C++ program?  MSDN website is not helpful.
Question by:monstro281
1 Comment

Accepted Solution

monstro281 earned 0 total points
ID: 24454173
Got it.
BOOL ScanForHardwareChanges() 
    DEVINST     devInst;
    CONFIGRET   status;
    // Get the root devnode.
    status = CM_Locate_DevNode(&devInst, NULL, CM_LOCATE_DEVNODE_NORMAL);
    if (status != CR_SUCCESS) {
        printf("CM_Locate_DevNode failed: %x\n", status);
        return FALSE;
    status = CM_Reenumerate_DevNode(devInst, 0);
    if (status != CR_SUCCESS) {
        printf("CM_Reenumerate_DevNode failed: %x\n", status));
        return FALSE;
    return TRUE;

Open in new window


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Log files are useful in diagnosing and repairing problems.  This is a list of common log files and their standard locations that I've compiled.   While this is not exhaustive, it is a pretty good list that I've found to be useful.  I may update it f…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question