Using AutoRun with a USB Flash Drive (USB stick)



The AutoRun technology in Windows is often used to start programs and open menu interfaces on a CD or DVD automatically. But it is possible to do the same with a USB flash drive (USB stick)? Can the AutoRun technology be used with a USB flash drive? In this article we will answer these questions.
 
Advertisement
Click here for more information about SamLogic USB AutoRun Creator
 
Note: Microsoft recently released an update for Windows XP and Windows Vista where the AutoRun for USB flash drives will function different compared to the text below. If you have downloaded and installed this update the AutoRun function will work in the same way as in Windows 7. You can read more about Autorun in Windows 7 in this article.
 
 
USB flash drive / USB stick
 
A typical USB flash drive
Most of us have a USB flash drive (sometimes also referred to as a USB stick, USB memory stick or a thumb drive) that we use when we want to store data temporarily. They are small and lightweight and are very practical when you want to move files from one computer to another. Previously we often burned our data to a CD or DVD, but using USB flash drives are faster and they are easier to handle and they can store more data, and they are so small that you can easily store them in your pocket.
 
USB flash drives are often used when data is moved between home and office. They are also often used when data is moved inside an office, for example when moving data to/from a computer that is not connected to a network. They are also practical if you want to run small special programs that don't need installation and which are not normally located on a computer.
 
Nowadays, companies have also started to distribute software, documents, movies and music via USB flash drives. One reason is that they are very fast - they are faster than CDs or DVDs. Programs that are placed on a USB flash drive start immediately and large documents are shown very quickly. But when distributing programs, documents etc. on a USB flash drive, the same question that was common with a CD or a DVD also arises. How can the end-user quickly find the program or document he/she wants to open?
 
With CDs and DVDs the AutoRun technology in Windows was used to start a particular program or open a particular document automatically. But is this also possible with a USB flash drive?


Using AutoRun with USB flash drives
 
If you place an Autorun.inf file in the root folder of a CD or DVD and the Autorun.inf file contains an OPEN command pointing to a program file (e.g. OPEN=MYAPP.EXE), the program is launched automatically when you insert the CD/DVD in a drive. But if you place the same Autorun.inf file and program file on a USB flash drive and plug the drive into a USB port in a computer, the program will not start automatically. Instead is a Windows menu shown, which contains a list of actions (options) that you can choose between to handle the USB drive.


The AutoPlay dialog box in Windows
 
The dialog box that is shown when you insert a USB stick in a computer is called the AutoPlay dialog box. This same dialog box is also shown when you insert a CD/DVD with no Autorun.inf file in a computer's disc drive.
 
With a CD or DVD this dialog box can be suppressed if an Autorun.inf file is placed on the disc. Unfortunately this is not possible, by default, with a USB flash drive. In Windows 7 this is not possible at all.
 
In Windows XP and Windows Vista it is possible for the user to change the behavior of a USB flash drive by changing settings in Windows, and there are programs available that can do this automatically. By changing some settings the user can make Windows to run the Autorun.inf file instead of showing the AutoPlay dialog box for USB flash drives. However, for security reasons this is not recommended and in Windows 7, with its tightened security, this possibility is completely removed.


So, how to launch a program on a USB flash drive?
 
Using Autorun.inf to automatically launch a program on a USB flash drive seems not to be possible in the same way as with a CD or DVD. So what to do instead? Are there any alternative ways?
 
Well, the answer is yes and no. It depends of the version of Windows. Below we will explain how to handle this in different Windows version.


How to launch a program in Windows XP and Windows Vista
 
As described above in this article, an AutoPlay dialog box is shown when the user plugs a USB stick into a USB port. This AutoPlay dialog box contains a list of actions (options) that can be performed on the USB flash drive, for example view a slideshow of pictures on the drive (if there are any) or open Windows Explorer. In Windows XP and Windows Vista it is possible to add your own action item (option) to the AutoPlay dialog box. This gives the USB flash drive almost AutoRun capability. The item is placed as the first option in the action list, and is selected by default, so the user only needs to press Enter or OK to launch the program. Not as automatic as using pure AutoRun, but almost.
 
To add this action item to the AutoPlay dialog in Windows, a command called ACTION must be placed in the Autorun.inf file. This command will display a user-defined text row in the AutoPlay dialog box (as the first text row) and it will co-operate with the OPEN command in the Autorun.inf file. The OPEN command specifies the filename of the program to execute. We will explain the ACTION command with more details below in this article, but first some words about Windows 7.


How to launch a program in Windows 7
 
In Windows 7 it is not possible to use the ACTION command and the OPEN command together with USB flash drives anymore. Microsoft has removed this support for security reasons. These commands are still available for CDs and DVDs in Windows 7, but not for USB sticks.

Specifying your own label and icon for the USB flash drive via the Autorun.inf file is still possible, but it is not possible to allow a user to execute a program on the drive via the AutoPlay dialog box. And automatically executing a program on a USB flash drive by turning off AutoPlay and only using AutoRun is not possible either. The OPEN command is not supported at all for USB flash drives in Windows 7.
 
To execute a program the user must open Windows Explorer and manually run the program. Luckily an option to start Windows Explorer is always shown in the AutoPlay dialog so it is easy to start Windows Explorer. But to make it also easy for the user to find your program on the USB flash drive (the program you want the user to start when plugging in the USB stick) you should always place the program on the root folder of the drive and give it a descriptive name such as "StartMe.exe", "Autorun.exe", "Menu.exe" etc. This program file should also be the only executable file in the root folder, otherwise some users might start the wrong program by mistake.
 
More information about the changed behavior for AutoRun and AutoPlay in Windows 7 can be read in the following article on our Internet site: Using AutoRun / AutoPlay with a USB Flash Drive in Windows 7.


Using the ACTION command in an Autorun.inf file
 
There are still a lot of users of Windows XP and Windows Vista so adding an ACTION command to the Autorun.inf file is still a good idea. It is also simple to add this command and below we will show an example of how this command can be used:
 
[AutoRun]
OPEN=MYAPP.EXE

ICON=MYAPP.EXE
ACTION=Start my application
 
In this example, the ACTION command places the text "Start my application" in the AutoPlay dialog box in Windows XP and Windows Vista. The item with this text will be placed as the first item and it will also be selected by default. Next to the text, the icon specified by the ICON command is shown. And when the user chooses the selected item, the program file specified by the OPEN command is launched.
 
If you use Notepad to create the Autorun.inf file, you should enter the following in Notepad:




How to give the USB flash drive a label (title)
 
It is also possible to give a USB flash drive its own label (title). This will work in all Windows versions since Windows XP, including Windows 7.
 
The label text will be shown in Windows Explorer and in the AutoPlay dialog box. To specify this text, a command with the name LABEL can be used in the Autorun.inf file. Below we show an example of how to use the LABEL command (the last line in the example):
 
[AutoRun]
OPEN=MYAPP.EXE

ICON=MYAPP.EXE
ACTION=Start my application
LABEL=My Drive
 
In this example the USB flash drive has been given the label "My Drive". This label is displayed before the drive letter in Windows Explorer and as a dialog box title in the AutoPlay dialog box. Below we show how the AutoPlay dialog box will look like in Windows XP when using the Autorun.inf file above:

AutoPlay dialog box in Windows XP

Specifying your own icon for a USB flash drive is also possible. In the example above we tell Windows to get the icon from the MYAPP.EXE program file by using a command named ICON. Instead of an .EXE file you can also use an .ICO (icon) file, for example as:
 
ICON=MYICON.ICO
 
More information about the LABEL and ICON commands, and other commands mentioned in this article, can be read on this page at Microsoft's web site: Autorun.inf Entries. A short commands reference is also available on this page on our web site: Autorun.inf - Commands.


Adding a menu interface to a USB flash drive
 
Example of an AutoRun menu interfaceThere are different reasons why a specific program should be run immediately after that a USB stick has been inserted into a USB port. One common reason is to start a general setup program. Another is to show a menu interface. This menu interface can for example contain buttons to start installations, show documents or show movies.
 
As described above in this article, different methods must be used in different Windows versions to start a particular program, for example to start a menu interface program. In Windows XP and Windows Vista the menu program can be launched almost automatically - just press Enter or OK - but in Windows 7 the menu program must be started manually by the user from Windows Explorer. To handle this in the best way you should do the following:
 
1. Give the program that should be started a descriptive name
2. Create an Autorun.inf file that adds an action item to the AutoPlay dialog box in Windows
 
You can for example name the program file to "START-MENU.EXE" and then create an Autorun.inf file with the following contents:
 
[AutoRun]
OPEN=START-MENU.EXE

ICON=START-MENU.EXE
ACTION=Show Menu
LABEL=My Menu
 
This file must be placed in the root folder of the USB flash drive. Also the menu program ("START-MENU.EXE") must be placed in the root folder, otherwise the Autorun.inf file above will not work. It is possible to place the menu program in a sub folder (then you must add a folder path to the OPEN and ICON commands) but it is not recommended as users will then have more difficulty finding the program.


Software that can create a menu interface to a USB flash drive
 
Although it is not complicated to create an Autorun.inf file, it is more time consuming to create a menu interface. There are many products on the market that can create menu interfaces for USB flash drives and some of them can also automatically create the necessary Autorun.inf file that is needed to add an action item to the AutoPlay dialog box in Windows. At our company we have a product named SamLogic CD-Menu Creator, which can be used to design and build menu interfaces for CDs, DVDs and USB flash drives.
  
   
Do you want to read more articles and tips?
 
If you want to read more articles and tips about AutoRun and related topics you can follow us on Facebook or Twitter, or subscribe on our newsletter. You can also read our blog.
Visit our Facebook page Follow us on Twitter Visit our video channel on YouTube
  
Related products:
SamLogic CD-Menu Creator
SamLogic USB AutoRun Creator


Other articles
More articles are available from the article index page.

 
USB Flash Drive Menu
 

Create a menu interface for a USB flash drive.
 

>
Read More Here
    


 
Related Articles
   

   

   

   

 
SamLogic
Article written by: Mika Larramo Spanish