Sunday, February 12, 2012

Windows 7 and Autorun.inf. Won't work from USB

I'm writing this post to let everyone know that the autorun.inf file will not automatically trigger from a USB drive in Windows 7.  I wrote a post (What is autorun.inf file) talking about the autorun.inf file because this can work for CDs/DVDs and other applications but WILL NOT work for auto starting a program from a USB drive. 

This used to be possible from a USB when I originally wrote the stuff in my files but since Microsoft removed it, its not anymore. I used it for a personal program I had on my USB so I didn't care about getting a virus from the USB.

As a rule of thumb, I always suggested people disable the autorun on their PCs to avoid viruses.  The reason for this is that if it is enabled and someone puts a USB in your computer, your computer can get a virus. It's insane how many people have viruses on their computer and don't even know it.  It's bad practice for people to put updates on a USB and just go computer to computer installing it that way for a few reasons.  First and foremost, its incredibly inefficient for deploying updates.  The second is the virus aspect.

Before you pass judgement on Microsoft for disabling this for USBs, look at the following:
If you insert a USB into your computer with autorun enabled and the autorun.inf pointing to an infected program, your computer now has it. Congrats! The autorun.inf viruses can really suck and wreck havok on things. Seriously bad news. Now in Windows 7, the virus will only transfer to your computer if you manually open the drive. This is great since you now have a chance to scan the drive and clean all viruses before opening it.

Saturday, February 11, 2012

All about 'Autorun.inf'

What is the 'Autorun.inf' file?
The file extension .inf stands for information file. The file is a simple text-based configuration file that tells the operating system (OS) how to deal open the presentation and treat the contents of the media (CD, DVD, USB thumb drive, etc). It tells the operating system which executable to start, which icon to use, and which additional menu commands to make available.
It defines the following:
  • The process or application that will automatically run when a disk is inserted
  • Optionally, one can define the process or application that will run for specific Operating environments.
  • The icon that will represent your application's CD or DVD when the drive is viewed with My Computer or Explorer.
  • Menu commands displayed when the user right-clicks the CD-ROM icon from My Computer or Explorer.
What does it contain?
There are 5 parts to this file: [autorun], [Content], [ExclusiveContentPaths], [IgnoreContentPaths], and [DeviceInstall]

  1. [AutoRun]
    1. This section is required for the file to be valid
    2. There can be one of these sections for the different operating systems (e.g. [autorun], [autorun.mips], [autorun.alpha], etc).  This is important so the appropriate executables run that are compatible with the computer the media is entered in.
    3. PURPOSE: contains the default AutoRun commands
    4. VALID KEYS:
      • Action
        • Specifies text to be ussed in the AutoPlay dialog to represent the program specified in the open or shellexecute keys.
        • VALUES: Text or '@[filepath\]filename, -resourceID 
      • Open
        • Specifies the path, file name and optional parameters to the application that AutoRun launches when a user inserts a disc in the drive
        • It is the CreateProcess function that is called by AutoRun.
        • VALUES: '[exepath\]exefile [param1 [param2 ...]]'
      • Icon
        • Name of a file resource containing an icon.  This icon will replace the icon of the drive when it is looked at from
        • VALUES: 'iconfilename[,index]'
        • EXAMPLE:
          • icon=MyProg.exe,1
      • Label
        • This will be the text label of the drive
        • VALUES: Text
        • EXAMPLE:
          • label=My Drive Label
      • shellexecute
        • Like the open command but this uses the machine's association information for the file type.
        • VALUES: '[filepath\]filename [param1 [param2 ...]]'
        • EXAMPLES:
          • shellexecute="Readme.txt"
          • shellexecute=[filepath\]filename[param1, [param2]...]
      • UseAutoPlay
        • Use AutoPlay rather than AutoRun
        • VALUES: boolean
        • EXAMPLE:
          • UseAutoPlay=1
      • shell\verb\command
        • Adds a custom command to the drive's shortcut menu.
        • Verb is a string with no embedded spaces.
        • Verb is also the text that will appear in the shortcut menu unless specifically altered to some other text
        • VALUES: '[exepath\]exefile [param1 [param2 ...]'
        • EXAMPLE:
          • shell\readit\command=notepad abc\readme.txt
            shell\readit=Read &Me
      • shell\verb
        • Optionally specify the text displayed in the shortcut menu for the verb above.
        • Use an ampersand (&) to select a hotkey for the menu.
        • VALUES: Menu Text
        • EXAMPLE:
          • shell\verb\command=Filename.exe
      • shell
        • Defines the menu command referred to by shell\verb as the default command in the shortcut menu.
        • The default command is the command executed when the drive icon is double-clicked.
        • If missing, the default menu item will be "AutoPlay", which launches the application specified by the open entry.
        • VALUES: Text
        • EXAMPLE:
          • shell=verb
  2. [Content]
    1. This section is not required
    2. PURPOSE: Allows authors to communicate the type and intent of content to AutoPlay without AutoPlay having to examine the media
    3. VALID KEYS:
      • MusicFiles
        • Values: boolean
      • PictureFiles
        • Values: boolean
      • VideoFiles
        • Values: boolean
    4. The key values will determine if the handlers associated with that contect type are displayed
    5. EXAMPLES:
      • [Content]
  3. [ExclusiveContentPaths]
    1. This section is not required
    2. PURPOSE: Limits AutoPlay's content search to only those folders listed, and their subfolders. The folder names are always taken as absolute paths (a path from the root directory of the media) whether or not a leading slash is used.
    3. EXAMPLE:
      • [ExclusiveContentPaths]
        \music\more music
  4. [IgnoreContentPaths]
    1. This section is not required
    2. IgnoreContentPaths takes precedence over ExeclusiveContectPaths so if a path given in a [IgnoreContentPaths] section is a subfolder of a path given in an [ExclusiveContentPaths] section it is still ignored.
    3. PURPOSE:AutoPlay's content search system will not scan the folders listed, nor their subfolders.
    4. EXAMPLE:
      • [IgnoreContentPaths]
        \music\more music
  5. [DeviceInstall]
    1. Used to indicate where driver files may be located
    2. Not used with AutoRun or AutoPlay and is only referred to during a driver installation phase
    3. Multiple key entries are allowed.
    4. PURPOSE: used to indicate where driver files may be located. 
    5. VALID KEYS:
      1. DrivePath
        1. Values: text (a directory path)
    6. EXAMPLE:
      • [DeviceInstall]
Simple example of an autorun.inf

action=Run PStart Program
label=My Portable PC

Complex example of an autorun.inf

open=filename.exe /argument1
shell\install = &Install
shell\install\command = setup.exe
shell\uninstall = &UnInstall
shell\uninstall\command = Uninstall.exe
shell\readme = &Read Me
shell\readme\command = notepad readme.txt
shell\help = &Help
shell\help\command = helpfilename.hlp

For more information see these associated blog posts: