Windows AutoPlay on a USB flash drive
I’ve been looking at using the AutoPlay functionality in Windows to launch an HTML document each time I insert a USB flash drive. Controlled using a file called autorun.inf, AutoPlay is designed for CDs, but I see no reason why it should not work with other removable media.
There is an excellent overview of the autorun.inf file on the Moon Valley Software website. Although autorun.inf files are easy to edit using a standard text editor such as Notepad, the Moon Valley Autorun.inf Editor is a free download from the Moon Valley Software website, which includes a particularly useful feature to locate and display icon resources within a .DLL.
Using this, I soon had a file which changed the icon and name for the USB flash drive when I inserted it, but I could not get it to automatically launch an HTML document.
After some searching (most notably a TechRepublic post), I discovered that the open command in autorun.inf only recognises programs. Windows 2000 and later recognise the shellexecute command to open other file types, for example:
[autorun]shellexecute=index.html
Once open= is replaced with shellexecute=, the context menu in Windows Explorer recognises index.html as the default action for the device, but for some reason it does not launch when I insert the USB flash drive into either of the PCs I’m using today. I checked out Microsoft knowledge base articles 155217 and 314855 but found the PCs were correctly configured to AutoPlay.
Searching the ‘net brought up a host of utilities (some free, some not) which are designed to extend the AutoPlay functionality, but by far the most useful utility was autorun.exe (a free download from the Tarma Software Research website, not to be confused with Peter Harrison’s AutoRun from the imagespro.com website). I found that autorun.exe would execute the commands in my autorun.inf file, but still not automatically launch when the USB flash drive was inserted.
Posted: 13:50 on Monday 11 October 2004 under Useful software, Windows.
Comments: 30
RSS (for comments on this post only)Share This
Comments
Comment from Peter Ling
Time: Monday 7 March 2005, 1:42
Hi, I am too looking for a solution to autoboot my usb flash drive. Your web blogg is excellent. Thank you. Further search takes me to ToroSoft who has a wonderful little proglet that sits on the system tray and look for your USB flash drive and then try to execute a predefine program, just like the Autoplay that you wish on a USB flash drive. Beware it is not autoplaay as such, but will function like one.
Keep up the good work. Cheers.
Peter Ling
Comment from yaodownload2006
Time: Monday 8 May 2006, 5:19
AutoRun is simply offers the best value, features, the most versatility, and employs the easiest to use interface on the market.
http://www.yaodownload.com/video-design/miscellaneous/autorun_miscellaneous.htm
Comment from seb
Time: Thursday 10 August 2006, 18:31
Any idea what to do if I want the USB drive to run on someone else’s computer when they insert it and they can’t do all the system configuration to sort it out.
(I’m looking to insert an intro screen on some promotional flash drives for my client.)
Comment from Charlie
Time: Tuesday 10 April 2007, 4:13
To get it to work on a usb you need to set open, action and label
for example:
[autorun]
open=example.exe
action=Launch example.exe
label=Some USB device
Comment from dobrix
Time: Friday 27 April 2007, 4:06
Still not working!!!
Comment from Alistair
Time: Sunday 6 May 2007, 14:26
This is a very interesting thread. I am looking for a similar solution. I have written an app that will be installed on a USB flash drive for portability. I want it to be able to plug in and run on any compatible system. I have looked over the solutions and all are good in their own way. Has anyone ever tried altering the disk label for the flash drive in some way to trick Windows into thinking it is another media type. Im no expert, just brainstorming.
P.S. Very nice blog!
Comment from unknown
Time: Wednesday 23 May 2007, 1:42
In my experiences the autorun.inf is of little use with windows XP but will do what you’re expecting in older versions of windows.
The “autoplay” is apparently a complete replacement to the autorun.inf functionality. At least for the USB memory drives..
Disabling autoplay unfortunantly doesn’t kick-in autorun.inf like one might expect, again, at least on a USB memory drive.
I imagine the only way around these sort of obstacles is going to be by making windows think the USB drive is a CD/DVD drive which still can AFAIK autorun something on it’s own accord. Then again it still might be needed to set autoplay on the machiine to actually do the expcted thing first.
IMO it’s mainly a problem with autoplay being too much, replying on specifics of the machine it’s run on. The older method was to just tell windows to autorun or not, the actual steps thereafter were all contained on the removable drive. Autoplay on the other hand relies on system specific settings beyond just do/don’t react when the drive is inserted/connected.
Comment from Nathan
Time: Monday 28 May 2007, 8:48
Excellent blog, cleared a few issues in my mind.
From what I understand the autorun feature is disabled is it can be used as an attack vector. Check out -
What must I do to trigger Autorun on my USB storage device?
http://www.microsoft.com/whdc/device/storage/usbfaq.mspx
and SCSI Inquiry Command
http://en.wikipedia.org/wiki/SCSI_Inquiry_Command
Anybody have any clue how to alter the firmware of the USB device please give me a shout!
Nathan
Comment from James
Time: Thursday 7 June 2007, 13:41
Charlie’s tip makes it easier to launch a batch file for me as it appears at the top the Autoplay menu but it still doesn’t do it by default. I feel that we’re very close. If the viruses that I catch from Internet cafes onto my USB drive can autolaunch then I should be able to do it too!
Anyone notice that there are two “AutoPlay” options in the right-click menu? One is in bold and correctly launches the file. The other is what actually happens when you plug in the device. I thought the bold was supposed to be default.
Comment from Nathan
Time: Tuesday 19 June 2007, 16:37
So has anyone figured this out? My entire flash drive is encrypted via truecrypt, and I’ve got a .wsf (Windows script file) that will pop up a password prompt. I’d like to autorun the wsf file so the password prompt will pop up when the drive is inserted. Seems like I’m close but no cigar.
Comment from sarah
Time: Wednesday 11 July 2007, 14:06
plz help my usb doesnt wrk. d lioght evn doesnt flash
Comment from inoesomestuff
Time: Saturday 4 August 2007, 22:07
I found this article very useful:
http://msdn2.microsoft.com/en-us/library/aa969327.aspx
Also, i found a CD-rom with this autorun file:
[Autorun]
open=rundll32.exe url.dll,FileProtocolHandler INDEX.HTM
ive experimented and tried to get get the open= to open a welcome.jpg but it does not seem to work, so i guess i will embed it into a html
there doesnt seem to be any information on msdn about this CLIENT_FILE= option…
Comment from Mana
Time: Friday 10 August 2007, 6:36
Hi..
I need the source code for the autorun.inf file for USB as i am unable to write the same myself. can anybody help me in this regard..??
Please do reply..
Thnx
Mana
Comment from Tom
Time: Friday 10 August 2007, 14:35
[Autorun]
Action=Tech Drive Menu
shellexecute=techdrivemenu.exe
Icon=User.ico
Label=Tech Drive
The above autorun.inf file not only has the option to open a menu off the flash drive but also when ever you double click the flash drive the menu pops up. I to have been trying to figure out how to get the USB drive to autorun a file upon connecting it to the PC, but have had no luck…
Comment from o. tempora
Time: Tuesday 14 August 2007, 17:35
As with #16 above, SanDisk’s Cruzer USB drives have two partitions, the first emulating a CD which launches subsequent apps. Though there are many sites that discuss how to hack Cruzer USBs, I’ve overlooked the one that tells how to actually create the fake CD. The CD partition contains the following files:
–autorun.inf
–Launchpad.zip
–LaunchU3.exe
and the autorun.inf is as follows:
[AutoRun]
open=LaunchU3.exe -a
icon=LaunchU3.exe,0
[Definitions]
Launchpad=LaunchPad.exe
Vtype=1
[CopyFiles]
FileNumber=1
File1=LaunchPad.zip
[Update]
URL=http://u3.sandisk.com/download/lp_installer.asp?custom=1.1.0.2&brand=cruzer
[Comment]
brand=cruzer
Comment from Aires
Time: Thursday 13 September 2007, 16:56
If my path for ‘Portable Firefox’ I:\FirefoxPortable\FirefoxPortable.exe then what kind of an autonrun file do I need to construct. I followed the tips above but couldn’t get it to work. I’ve got a SanDisk Cruzer Micro 1.0GB flash drive - I need an autorun file that’ll work on any PC and isn’t restricted to just my I:\ drive.
Comment from Mr Jose Cuervo
Time: Thursday 24 January 2008, 18:29
I have had success in “hacking” the U3 software to enable me to mount any ISO image on the CD partition. I developed a program that will scan a system for devices missing drivers and load them directly from the flash drive.
since it is based on the U3 partition (their software was not used) it will autoplay any image on any system.
I made this for my own use but have considered offering my knowledge on ebay to mount images on flash drives. I am not really sure I would want to tell others how because there are a lot of malicious ways that this can be exploited. I will check back here if any of you are interested.
Bob
Comment from Sven
Time: Monday 18 February 2008, 9:34
This is really nice blog. I didn’t understand all what you wrote because my english is not perfect. I still need help. What I must do if I want make USB stick what automatically open eg. www.google.com site?
Thanks a lot for help.
Comment from Sven
Time: Monday 18 February 2008, 16:05
I found one good site but it isn’t solved my problem. I want it works without “What do you want Windows to do” - box.
http://dailycupoftech.com/usb-drive-autoruninf-tweaking/
I also read it’s possibly to do if I use U3-memory stick but I don’t have it. I have normal Kingston DataTraveler100 sticks.
Is it possibly autorun.inf open eg. open.bat file and that file open website without any question?
Comment from Aires
Time: Saturday 23 February 2008, 14:11
Bob I’m definitely interested - please post some additional info.
Comment from Chris
Time: Tuesday 22 April 2008, 16:53
Just a little note…
What you are talking about here is a file system issue.
a USB drive will normally use FAT32 file system and will be seen by windows as a mass storage device. autorun.inf was made for devices such as CD Rom’s not hard drives.
You can tweak your settings to autoboot a USB drive but that’s not much cop if you just want to give someone a key and let them run it.
To achieve the autoboot you need to fool the operating system into thinking that a partition of the USB device is actually a CD Rom using the CDFS file system which will autorun autorun.inf with no issues.
This has to happen at a hardware level with 2 physical partitions on the drive.
You can buy one of these USB pens online.
Hope this helps
Chris
Comment from Mike Metcalf
Time: Thursday 1 May 2008, 21:37
Thanks to all who have contributed to this blog. The information contained here was very helpful to me.
I was wanting to take my IE favorites with me on a flash drive so that as I bounce from computer to computer I can plug it in and get right to the sites I have bookmarked.
It turned out to be incredibly simple. (after an hour of trial and error) I exported my favorites from IE to the flash drive (saved as bookmark.htm) and added an autorun.inf file containing the following entries:
[autorun]
action=My Internet Favorites
icon=happy.ico
open=explorer bookmark.htm(happy.ico is an icon of a happyface I added just for fun)
Now when I plug the drive into a USB port, the Windows autoplay box has as the default option: My Internet Favorites
Hitting enter opens the web page (bookmark.htm) containing all of my bookmarked favorites.
Hopefully, this info will help someone else find their solution as well.
Mike
Comment from divicme
Time: Sunday 11 May 2008, 23:18
as far as i see, the challange of running a program when that flash drive is plugged in,without windows screen, is still continuing.
i want the same thing, but i dont have the proper knowledges to do it.
….i’m waiting for a clever one !

Write a comment
Please note the rules for comments and the privacy policy and data protection notice. I'm sorry but, because not everyone sticks to the rules, I've had to implement some spam prevention measures - if you're experiencing difficulties leaving a comment, please let me know.