Thursday, 20 August 2015

How To Enable/Disable USB Port Using C Programming

Every Computer/Laptop contains  USB ports(commonly 4 ports) that are used to insert Pen Drives,Modems,External HDD,Mouse & Keyboard and so on.

But do u know that Ports can be Enabled or Disabled ???

Yes,it is.

Normally that ports are in Enable state.But if u Disable it then it acts like a broken ports like if u insert some Pen drive or modem e.t.c. then that devices can not read into your windows explorer


 Here is C Code to manipulating usb port (both Enable+Disable)  >>>>>

#include<stdio.h>
#include<conio.h>
#include<windows.h>


COORD coord = {0, 0};
COORD max_res,cursor_size;
void gotoxy (int x, int y)
{
        coord.X = x; coord.Y = y;
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
};

void main()
{

int choice;
gotoxy(35,4);
printf("Enter choice >>>>>>\n");
gotoxy(35,6);
printf("1.Enable USB Ports\n");
gotoxy(35,7);
printf("2.Disable USB Ports\n");
scanf("%d",&choice);

if(choice==1)
/*enable USB ports*/
system("reg add HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR \/v Start \/t REG_DWORD \/d 3 \/f");
else if(choice==2)
/*disable USB ports*/
system("reg add HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBSTOR \/v Start \/t REG_DWORD \/d 4 \/f");
else
printf("\ninvalid choice");

}

 Paste it into your compiler & then compile and run.

After Disable ,you should enable it again otherwise usb port not working.


Thnxx for reading this.
Plz like our facebook page to give us support.

Fell free to comment if u don't understand it's mechanism.

No comments:

Post a Comment