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

  • Home
  • SEARCH
  • 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 8658819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:51:33+00:00 2026-06-12T15:51:33+00:00

I need to programatically uninstall all Com port devices. The issue is that these

  • 0

I need to programatically uninstall all Com port devices. The issue is that these Com Port Devices are not present and therefore completely hidden. Meaning, even if you want to uninstall them using device manager, first you have to add devmgr_show_nonpresent_devices = 1 to your environment variables and then show hidden devices in device manager. Then, you can right click each device and uninstall. I don’t want to uninstall the associated driver though. I am adding that variable under advanced system settings, creating and saving a new user variable.

I try to do this with devcon. They can be found with devcon findall but I cannot remove them because the command to remove them fails stating no device has been uninstalled. Also, there is not flag to have it look for non-present devices. If I do a standard devcon find, no devices are found (of interest).

So, I am back to being forced to figure out how exactly to do this using my own code and here is where I get stuck. Here is what I have so far:

// Get all of the devices
PCTSTR enumType = "PORTS";
HDEVINFO devs = NULL;
devs = SetupDiGetClassDevs(NULL,enumType,0,DIGCF_PRESENT | DIGCF_ALLCLASSES);

// Loop through the devices
DWORD devCount = 0;
SP_DEVINFO_DATA devInfo;
int enumeratingDevices = 1;
devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
while(enumeratingDevices){
    enumeratingDevices = SetupDiEnumDeviceInfo (devs,devCount,&devInfo);
    // Uninstall each device
    cout << SetupDiRemoveDevice(devs,&devInfo);
    cout << SetupDiCallClassInstaller(DIF_REMOVE,&devInfo,NULL);
    devCount++;
}
cout << devCount;
SetupDiDestroyDeviceInfoList(devs);
return 0;

Right now I am getting an output of 001. So, basically, SetupDiEnumDeviceInfo() orSetupDiRemoveDevice do not run correctly. I know that the enumeration is working because if I put in enumType = "USB"; I get ten for the devCount.

Any help or advice would be great.

  • 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-12T15:51:34+00:00Added an answer on June 12, 2026 at 3:51 pm

    So, I figured it out after a lot of tinkering and reading.

    // Get all of the devices
       //This enumeration does not work in general, instead passing
       //complete id of the device is probably best. 
       //It is helpful to know the vendor and device ID
    PCTSTR enumType = "PORTS"; 
    HDEVINFO devs = NULL;
    devs = SetupDiGetClassDevs(NULL,enumType,0,DIGCF_ALLCLASSES);
    
    // Loop through the devices
    DWORD devCount = 0;
    SP_DEVINFO_DATA devInfo;
    int enumeratingDevices = 1;
    /*This line is essential*/
    devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
    while(enumeratingDevices){
            enumeratingDevices = SetupDiEnumDeviceInfo (devs,devCount,&devInfo);
            // Uninstall each device
            if(enumeratingDevices){
               SetupDiRemoveDevice(devs,&devInfo);
               devCount++;
            }
    }
        //Clean up
    SetupDiDestroyDeviceInfoList(devs);
    

    I will update this tomorrow when I get to the lab with the exact enumeration I was talking about. However, with this method, you can uninstall virtually any device even if it is not present and just a “ghost” in the registry.

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

Sidebar

Related Questions

I need to trigger the hover state of a Flex button programatically, so that
I need a way to programatically detect whether the monitor is wide or not,
Appreciate that the WP7 ApplicationBarIcon is not standard control as such. I need to
I am programatically generating a SQL statement that I then need to execute, however
In asp.net mvc 2 I need to get programatically all the views thar are
I have a windows application that I need to be able to manipulate programatically.
I need to programatically determine if my app is running in development or not,
I have a url (http://www2.anac.gov.br/aeronaves/cons_rab.asp) where I need to post form data programatically. That
I need to programatically append to a multi-page TIFF or PDF a new image.
I need to programatically encrypt a directory of files, like in a .zip or

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.