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");
}
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.
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");
}
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.