Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8755669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:53:59+00:00 2026-06-13T13:53:59+00:00

I know how to use the Setup API to enable and disable devices. What

  • 0

I know how to use the Setup API to enable and disable devices. What I need to know is, can I use this same API to determine if a device is enabled/disabled? I think the real question is how to use it thusly because Microsoft’s devcon uses the Setup API for its manipulation of hardware and that program will tell you if a device is enabled or disabled (as does the Device Manager). How is this done? My research of the Setup API methods to this point doesn’t show a clear answer.

Andy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:54:00+00:00Added an answer on June 13, 2026 at 1:54 pm

    This API from MS has got to be among the least used, understood and worst documented. As I mentioned in my original post, the Setup API can be used to enable/disable hardware. So, I thought I would take a few moments and supply the community with how I finally figured out how to check the status of hardware.

    So, the short answer: you don’t do this from the Setup API. Of course, this makes sense. After all, since you can change the devices state, i.e. enable or disable, using the Setup API: it naturally follows that you’d have to use a completely different API to determine the device’s current state. Now, enter the Configuration Manager 32 API. To enable/disable hardware, you have to use the Setup API, but to figure out what state the hardware is in, you have to use the ConfigMgr 32 API (#include cfgmgr32.h). Makes sense, right?

    There may be other ways of doing this, but here’s what I did.

    #include <Windows.h>
    #include <cstdlib>
    #include <setupapi.h>
    #include <cfgmgr32.h>
    
    GUID driveGuid = {0x4d36e967, 0xe325, 0x11ce,
        {0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}};
    
    // first, get a list of hardware you're interested in using Setup API
    HDEVINFO hDevs(SetupDiGetClassDevs(&driveGuid, NULL, NULL, DIGCF_PRESENT));
    if(INVALID_HANDLE_VALUE == hDevs)
    {
        throw std::runtime_error("unable to build a list of hardware");
    }
    
    /* this struct has the dev instance ID that the CFG MGR API wants.
     * The struct must be must be inited to the size of the struct,
     * the cbSize member, all others should be 0
     */
    SP_DEVINFO_DATA devInfo = {sizeof(SP_DEVINFO_DATA)};
    DWORD index = 0;
    LONG devStatus = 0, devProblemCode = 0;
    char devId[256];
    memset(devId, 0, 256)
    while(SetupDiEnumDeviceInfo(hDevs, index++, &devInfo))
    {
        // use Config Mgr to get a nice string to compare against
        CM_Get_Device_ID(devInfo.DevInst, devId, 256, 0);
    
        /* use whatever mechanism you like to search the string
         * to find out if it's the hardware you're after
         */
        if((std::string(devId)).find("MyHardware") != std::string::npos)
        {
            // goody, it's the hardware we're looking for
            CM_Get_DevNode_Status(&devStatus, &devProblemCode, devInfo.DevInst, 0);
    
            /* if the call to getting the status code was successful,
             * do something meaningful with the data returned.
             * The fun part of this is that the return codes aren't
             * really documented on MSDN.  You'll have to look
             * through the CfgMgr32.h file.  Incidentally, these values
             * are what are shown in the Device Manager when you look
             * at the device's status.
             */
        }
    }
    
    SetupDiDestroyDeviceInfoList(hDevs);
    

    You’ll have to figure out the GUID for the hardware you’re after by searching through the list found here. Some of these, at least, are predefined in various Windows headers. However, at this point, I know of very few and have only stumbled onto them by accident.

    Relevant links to the functions used above:
    SetupDiDestroyDevieInfoList
    CM_Get_DevNode_Status
    CM_Get_Device_ID
    SetupDiEnumDeviceInfo
    SetupDiGetClassDevs
    SP_DEVINFO_DATA

    I hope this helps someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Somebody know how use OpenX (php app) with Django? I need to use OpenX
I know you use the C based networking API to do FTP communication but
If I use the ImageShack API just in a form like this: <form method=post
This is simplified setup - I have API (I have n o control on
I can't use the XPS API since the program has to be able to
I know the use of WCF in SA is deprecated because it will move
I know and use eric meyer CSS reset, but is there any more things
I know and use the standard c# regex library, and I love it. It
Now i know to use the method of float.Parse but have bumped into a
so far i only know to use Ctrl-Shift-A to do SVN in TextMate. is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.