Home / C Tutorial / USB Port Programming in C | Enable or disable USB ports

USB Port Programming in C | Enable or disable USB ports

Hey friends, today we are going to discuss things about 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 | Enable or disable USB ports

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 , 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 . If you have any queries or doubts ask us in form of comments.

 

About Mr Coder

Well, I am software programmer and love to code. My hobbies is to do Hacking, Coding, Blogging, Web Designing and playing online games. Feel free to contact me at shiviskingg@gmail.com or lokesh@hackingloops.com

Check Also

C Language Class 1 : Introduction to C Programming Language

C Language Class 1 : Introduction to C Programming Language C was developed in the …

14 comments

  1. mohammed salahuddin

    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 …

  2. 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. 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. Regards for helping out, good information. “I have witnessed the softening of the hardest of hearts by a simple smile.” by Goldie Hawn.

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

  6. 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. 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. 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. it is showing Runtime in C : Error “reg” illegal Command .. What To Do Help Me On This

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

  11. 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. what does this line means? \/v Start \/t REG_DWORD \/d 4 \/f”

  13. 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 Reply

Your email address will not be published. Required fields are marked *