February 3, 2011

C Program to Disable and Enable Usb Port





In this post I’m going to show you how we can Disable and Enable USB Port. By blocking the usb port we can control whether user to access the machine or not.

Many schools and colleges have no pen drive rule, for that they are blocking the usb port. This trick will help us to open the blocked usb port.

This is very small and easy code, once the block usb program executed the computer will not recognize any inserted usb drive, but we can reverse it by unblocking the usb port.

This program tested on XP but not sure about vista & windows 7. You can try this program on your own computer, as I have given the unblock code also

Logic of the program
The logic of the program is simple. The 'C' source file block_usb.c writes the DWORD value of 4 (100 in binary) in the registry settings at "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start" to 'lock' the USB ports.

Similarly, in the inverse process, the 'C' source file Unblock_usb.c writes the DWORD value of 3 (011 in binary) in the registry settings at "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start" to 'unlock' the USB ports.


CODE
To disable usb port
#include<stdio.h>
void main()
{
system("reg add HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR \/v Start \/t REG_DWORD \/d 4 \/f");
}

Save this code as block_usb.c and open it with turbo c compiler, after compilation it will create a block_usb.exe which is a simple program that will disable (block) all the USB ports of the computer.

refer my article  To install turbo c compiler

After execution of block_usb.exe insert your pen drive, computer will not detect it. Now here’s the unblock code
To enable usb port
#include<stdio.h>
void main()
{
system("reg add HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR \/v Start \/t REG_DWORD \/d 3 \/f");
}

Save this code as unblock_usb.c and compile it with turbo c to get the unblock_usb.exe

Execute the unblock_usb.exe and now the computer detecting your pen drive.

I have also created rar file containing c source code of block and unblock usb and the executable files. Download from here


hope you liked this post, please comment below to express your feelings… :)

Related Posts :



Categories: ,

10 comments:

i tried in windows 7. but it didn't work
block.exe is not been creating anywhere.
please tell me where it(exe file) should be created?
should it be created in c:/tc/bin ??

after u pressed CTRL+F9 the exe file will b created in the folder where u saved the block_usb.c.. it will be not created in c:/tc/bin

This program tested on XP but not sure about vista & windows 7

and I have also created rar file containing c source code of block and unblock usb and the executable files. DOWNLOAD LINK PRESENT AT THE END OF THE POST..

KEEP VISITING.. :)

Good job men Tell me what more you can disable for example the ethernet port? it is posible? which is the code my email is estebanlerma514@gmail.com

thank u.. :) i'll try to find solution for that & will let u know

i am facing the problem of "insert #1 disk in drive c" while installing.
i am not able to solve it.please help me.

You mean at the time of Turbo C Installation.. if it is so then do this..
1st download turbo c and extract to the folder then copy paste that folder in anywhere c drive(like desktop,c drive,downloads) just anywhere in c drive and try installing turbo c this will defiantly work.. :)
here are complete and easy steps to install turbo c.. http://www.mycfiles.com/2011/02/how-to-install-turbo-c-compiler.html

error> unknown escape sequence \/

Hi,
For windows 7 the only tweak is to run it as Admin.
Put a getchar() towards the end of the function, and you'll see the message, "Operation Failed", as you're not the admin.

Instead now run it as Admin, you'll see "Operation Successful" message.

It worked on Windows 7 Ultimate edition too.

If a usb peripheral is already plugged in then it doesn't block the ports.
We have to remove all peripherals & then run again.

Same while unblocking.

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Related Posts with Thumbnails