If you ever share thumb drives with a friend or co-worker, there’s a good chance they might infect your computer via their thumb drive. If your friend’s computer has a virus that can be transmitted via thumb drive, when they pass the drive to you, it may automatically run and infect your computer. The trick is to turn off AutoPlay for all drives on your computer. Here’s how:

In Windows 7 from the Control Panel, click on Autorun and then uncheck the box at the top of the screen. Now thumb drives won’t run automatically.

On other version of Windows :

XP – install TweakUI – run it and go to My Computer – AutoPlay – Drives – you can then deselect any drives which you don’t want to run automatically. You can also from the same interface go to “Open My Computer” and then right click on the thumb drive and choose Properties – I then usually check – Open with Windows Explorer.

Or, in any Windows version:
1. Launch the Registry editor Start – Run – regedit)
2. Find HKEY_CURRENT_USER\Software\Microsoft\Windows\
CurrentVersion\Policies\Explorer
3. Double-click NoDriveTypeAutoRun in the right-hand pane and set its value to hexadecimal FF. (To turn it back on, change the value to 91)