Solved

Enable / Disable USB without using the registry

Posted on 2008-06-10
1
2,241 Views
Last Modified: 2013-12-14
i would like to Enable and Disable USB ports. I have read that it can be done by changing the registry value but the problem is you need to restart or remove and attached again the usb device... i nedd to disable and enable it on the time the usb is attached.

i have read that it can be done using the SetupDiCallClassInstaller, but i dont know how to use it and perform it in mfc..is there anybody who can give some sample about this matter.

many thanks
0
Comment
Question by:haroldxious
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
Comment Utility
See http://www.codeproject.com/KB/system/HwDetect.aspx ("Detecting Hardware Insertion and/or Removal"), especially this section:

--------------------------------------------->8---------------------------------

Disable a device

Suppose you have the correct HDEVINFO and SP_DEVINFO_DATA (actually, we save the dbcc_name as the tree node extra data and retrieve that data when we right click on the device icon and then call SetupDiGetClassDevs and SetupDiEnumDevicInfo), the flow to disable a device is as follows:

   1. Setup the SP_PROPCHANGE_PARAMS structure properly
   2. Call SetupDiSetClassInstallParams() and pass-in the SP_PROPCHANGE_PARAMS structure
   3. Call SetupDiCallClassInstaller() with DIF_PROPERTYCHANGE

--------------------------------------------->8---------------------------------

The article comes with full source code.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now