At present, various USB flash drive viruses are rampant, especially the computers in my lab will be used by others. They are very worried about the viruses on the USB flash drive, some time ago, I disabled the USB interface in the CIMS parameter. However, it was very troublesome to restart the computer to start the USB interface.
How to Use Program How to disable and start the USB interface? How can you make your computer use only your USB flash drive?
If you are interested, continue.
1. Reload the Windows message receiving function in the form1 class to detect USB flash drive insertion.
2. Check the authentication information of the USB flash drive.
3. If the authentication is not your USB flash drive, use the shell. dll component of the Windows Shell. Right-click the USB flash drive and choose "pop-up" from the menu ".
Note: 1. You can put a text file (txt, Excel, INI, RTF, XML, etc.) in your USB flash drive to store the password information. The password is used as the authentication credential.
2. You can use shell. DLL to call almost all shortcut menus in windows. Article Source code has been provided), of course, it is also possible to execute the USB flash drive format. If the virus is prevented, it is detected that the USB flash drive is inserted, and the direct format is good.
Main source code:
1. Verify USB flash drive insertion Code
Constint dbt_devicearrival = 0x8000;
Const int dbt_deviceremovecomplete = 0x8004;
Protected override void wndproc (ref message mess)
{
Try
{
If (M. MSG = wm_devicechange)
{
Switch (M. wparam. toint32 ())
{
Case dbt_devicearrival: // USB flash drive
Driveinfo [] S = driveinfo. getdrives ();
Foreach (driveinfo drive in S)
{
If (drive. drivetype = drivetype. removable)
& (Drive. Name. tostring () = ":\\"))
{
// Listbox1.items. Add ("the USB flash drive has been inserted, and the drive letter is :"
+ Drive. Name. tostring ());
// MessageBox. Show ("USB flash drive inserted! Drive letter: "+ drive. Name. tostring
(), "NOTE ");
Tan_chu ();
Break;
}
}
Break;
Case dbt_deviceremovecomplete: // unmount the USB flash drive
// MessageBox. Show ("the USB flash drive has been detached. ");
Break;
Default:
Break;
}
}
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}
Base. wndproc (ref mess );
}
2. Pop-up USB flash drive code
Static private void tan_chu ()
{
Shell32.shell SH = new shell32.shell ();
Shell32.folder Sf = Sh. namespace (17); // Diann
Shell32.folderitems FS = SF. Items ();
While (true)
{
Try
{
For (INT I = 0; I <fs. Count; I ++)
{
String itemname = Fi. Item (I). Name. tostring ();
If (itemname = "removable disk (K :)")
{
Shell32.folderitemverbs fivs = FCM. Item (I). verbs ();
Foreach (shell32.folderitemverb FV in fivs)
{
String name = FV. Name. tostring ();
If (name = "pop-up (& J )")
{
FV. doit ();
// Break;
}
// If (name = "Scan virus (& K )")
//{
// FV. doit ();
//// Break;
//}
}
}
}
}
Catch (exception ex)
{
String Exx = ex. Message. tostring ();
}
}