By default Windows vista and Windows 7 has the auto play feature turned on. Auto play scans the content of the CD or the portable storage device attached and plays or runs the content automatically. This feature is intended for the novice computer user who may not know how a media CD or a software CD can be used. In the case of a software CD, the file autorun.inf contains the name of the executable that needs to be executed automatically.
However this feature is dangerous since it can also automatically start malicious software contained in a portable storage device such a USB pen drive. Prior to Windows XP service pack 2, autorun was disabled for removable storage devices such as USB sticks and zip drives. In vista and Windows 7, autorun is enabled for all devices.
It is highly recommended that you turn off autorun in your Windows machine. This prevents accidental virus infection where you unknowingly insert a virus infected USB pen drive and autorun starts a virus program. For example, you might take your USB pen drive to an internet cafe to download some text files. The computer at the cafe might be infected and the virus will get into the USB pen drive. Since autorun is enabled on your machine, it will also get infected. Turning off auto run helps in preventing such accidental virus infections.
How to disable autorun in Windows 7
Press Windows key + R to bring up the "Run console". You can also invoke it from Start -> Accessories -> Run menu. Type in "gpedit.msc" without the quotes and press enter.
This will open the Local Group Policy editor. From the left tree menu, expand Computer Configuration -> Administrative Templates -> Windows Components -> AutoPlay Policies. Click on AutoPlay Policies as shown below.
From the right side, double click on Turn off Autoplay (or you can right click and select the edit menu). This opens up the following screen,
As shown above, select the "enabled" option and click on apply. It may seem strange, but in Windows 7 you need to enable the disabling of autoplay! Now you no longer need to worry about viruses that automatically gets triggered when you connect a USB pen drive.