-
August 7th, 2007, 04:25 AM
#1
Enable/Disable USB drive
Hi,
I want to Enable/Disable USB drive programatically.
I dont to use devcon.exe.
If anyone knows some API please tell me.
Thanks in advance.
-
August 7th, 2007, 08:51 AM
#2
Re: Enable/Disable USB drive
What do you mean by Enable / Disable ¿
Do you want to programmatically disconnect the USB device ¿
If you want to determine if the USB device was inserted or taken out, you can use the [b]RegisterDeviceNotification{/b] API with the UnregisterDeviceNotification API. You'd also need to catch the WM_DEVICECHANGE event with either DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE
You could also programmatically show the "Safely Remove Hardware" box by using RunDLL32.exe and reference HotPlug.dll
Is that what you mean ¿
-
August 7th, 2007, 11:13 PM
#3
Re: Enable/Disable USB drive
Disable means even if user plugs in the USB drive, the drive letter should not appear in my computer.
-
August 8th, 2007, 12:55 AM
#4
Re: Enable/Disable USB drive
Originally Posted by bsharda
Disable means even if user plugs in the USB drive, the drive letter should not appear in my computer.
Honestly, why do you want to do that ¿
-
January 25th, 2008, 03:54 AM
#5
Re: Enable/Disable USB drive
hi,
Have u found out how to enable and disable the usb port ?
if so could u please help me?
-
January 25th, 2008, 04:20 AM
#6
Re: Enable/Disable USB drive
Hi,
If you are just trying to use it in Kernel level, i hope http://msdn2.microsoft.com/en-us/library/aa476213.aspx
is useful, i have got it for good.
If you are planning to write Assembly language for any other OS, then i think you need to control interrupt for the respective PORT.
Have a great way.
Cheers
Marqu
-
July 22nd, 2014, 05:18 AM
#7
Re: Enable/Disable USB drive
Originally Posted by Marqu
Hi,
If you are just trying to use it in Kernel level, i hope http://msdn2.microsoft.com/en-us/library/aa476213.aspx
is useful, i have got it for good.
If you are planning to write Assembly language for any other OS, then i think you need to control interrupt for the respective PORT.
Have a great way.
Cheers
Marqu
Hi, The link provided is not working anymore and says content closed. Do you have the webpage ? or any kind of information on that. Can u please help me with the way I can disable/block usb ports and if needed then enable them again..
-
July 22nd, 2014, 05:53 AM
#8
Re: Enable/Disable USB drive
Originally Posted by ajaytvish
Hi, The link provided is not working anymore and says content closed.
No, it says:
This content has been removed.
Originally Posted by ajaytvish
Do you have the webpage ? or any kind of information on that. Can u please help me with the way I can disable/block usb ports and if needed then enable them again..
I'd just repeat Hannes's question (from the post#4):
Honestly, why do you want to do that?
Victor Nijegorodov
-
July 23rd, 2014, 05:30 AM
#9
Re: Enable/Disable USB drive
1) disable the driver (don't forget to reenable it, this is kinda drastic)
-> ZwUnloadDriver/ZwLoadDriver (see MSDN)
needs UAC elevation or to be called from kernel mode. (you'll need a driver for this)
2) disable the USB port (again, don't forget to reenable it, still kinda drastic)
SetupDiXxxx api's to set the state to enabled/disabled.
iirc, you'll need SetupDiSetClassInstallParams and SetupDiCallClassInstaller at least, you'll probably also need a bunch of code to enumerate all the ports on the bus. (see MSDN)
alternatively get the DDK, and use the DevCon tool (which you can call with any one of the CreateProcess() type functions).
again, needs UAC elevation.
3) 'eject' or 'disconnect' the device.
You can do this via the PnP Configuration Manager.
You'll also need to monitor changes when USB devices get plugged in/out that you want to disable/eject/disconnect. There's functions in WMI to do this.
Not all devices will respond to 'eject' or 'disconnect' commands and continue working happily.
See: DevEject (c++) or USBEject (C#)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|