USB Port Programming in C | Enable or disable USB ports

Mr Coder August 15, 2012 14



Hey friends, today we are going to discuss things about USB port programming in C. In this tutorial, i am going to show you how to enable or disable USB Ports in windows. By blocking the usb port we can control whether user to access the machine or not. Many schools, colleges, offices have no USB drive rules i.e. USB ports are blocked. This trick(C program) will help us to open the blocked usb ports.

USB port programming in C

This is 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 and Windows 7 . You can try this program on your own computer, as I have given the unblock code also.

How the Logic of USB port programming in C works ?

USB port programming in C is itself a cool phenomenon. The logic of the USB programs is quite 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.

C Code to disable USB ports :

#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 USB ports of the computer.

 

C Program to Enable USB ports :

#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 and Execute the unblock_usb.exe and now the computer detecting your pen drive.

We hope you all have enjoyed the USB port Programming in C tutorial. If you have any queries or doubts ask us in form of comments.

 



14 Comments »

  1. mohammed salahuddin October 10, 2012 at 12:47 pm - Reply

    Hi Lokesh,

    I am web designer and I tried this program on windows 7 Home Basic 64 bit. It shows an alert that this program is not compatible with the version of windows you are running …

    • Mr Coder October 10, 2012 at 7:29 pm - Reply

      Its because, in windows 7 registry editing is restricted for security reasons.

  2. guild wars 2 gold October 11, 2012 at 1:19 am - Reply

    Thank you for the good writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! By the way, how can we communicate?

  3. diablo 3 gold October 11, 2012 at 3:35 pm - Reply

    I truly appreciate this post. I have been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again

  4. ugg outlet online October 13, 2012 at 1:29 pm - Reply

    Regards for helping out, good information. “I have witnessed the softening of the hardest of hearts by a simple smile.” by Goldie Hawn.

  5. Troy Aziz November 3, 2012 at 1:02 pm - Reply

    This is an excellent article. You get my vote and I will bookmark this weblog now.

  6. chanel classic flap bag November 4, 2012 at 10:32 am - Reply

    I will right away grasp your rss as I can not find your e-mail subscription link or e-newsletter service. Do you have any? Please permit me know in order that I may subscribe. Thanks.

  7. Shane Luttrull November 4, 2012 at 6:55 pm - Reply

    It’s a pity you don’t have a donate button! I’d without a doubt donate to this fantastic blog! I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to new updates and will share this blog with my Facebook group. Talk soon!

  8. snappzmarket apk November 5, 2012 at 5:43 pm - Reply

    Wow, marvelous blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your site is excellent, as well as the content!. Thanks For Your article about USB Port Programming in C | Enable or disable USB ports .

  9. Vish. December 13, 2012 at 5:26 pm - Reply

    it is showing Runtime in C : Error “reg” illegal Command .. What To Do Help Me On This

  10. Nikhil February 25, 2013 at 7:07 am - Reply

    Hi,
    Mr coder thanks a lot.for the help given by you.
    Thank you very much…….

  11. Carrie Barninger May 21, 2013 at 10:44 am - Reply

    Wow, fantastic blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your site is fantastic, as well as the content!. Thanks For Your article about USB Port Programming in C | Enable or disable USB ports .

  12. john fred June 15, 2013 at 12:43 am - Reply

    what does this line means? \/v Start \/t REG_DWORD \/d 4 \/f”

  13. Mike October 1, 2014 at 11:50 am - Reply

    Looks tricky, but from this to really manage an USB port in C++ it’s a long distance. Witch would be the code to cover it?

Leave A Response »