Solved

Enable / Disable USB without using the registry

Posted on 2008-06-10
1
2,257 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
ID: 21756478
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
fizzArray  challenge 1 58
Best IDE for PHP starters 11 113
Change to event 1 100
how to use laptop or pad camera in vb.net windows application 2 45
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

914 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

19 Experts available now in Live!

Get 1:1 Help Now