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.

Comments

43 responses to “Windows AutoPlay on a USB flash drive”

  1. Peter Ling avatar
    Peter Ling

    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

  2. Mark avatar

    Peter, thanks for your feedback and I’m glad you found this useful.

    I haven’t tried the Torosoft AutoRun USB software but from a quick glance at the website it certainly looks interesting.

  3. Mark avatar

    Autoplay in Windows XP: automatically detect and react to new devices on a system (from MSDN) provides a comprehensive review of AutoPlay functionality.

  4. yaodownload2006 avatar
    yaodownload2006

    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

  5. seb avatar
    seb

    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.)

  6. Charlie avatar
    Charlie

    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

  7. Mark Wilson avatar

    Charlie – thanks for that tip :-)

    Mark

  8. dobrix avatar
    dobrix

    Still not working!!!

  9. Alistair avatar

    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!

  10. unknown avatar
    unknown

    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.

  11. Nathan avatar
    Nathan

    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

  12. James avatar
    James

    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.

  13. Nathan avatar
    Nathan

    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.

  14. sarah avatar
    sarah

    plz help my usb doesnt wrk. d lioght evn doesnt flash

  15. Mark Wilson avatar

    OK, so this is what I have in my autorun.inf these days (tested under Windows Vista):

    [autorun]
    open="notepad contents.txt"
    action="notepad contents.txt"
    shellexecute="notepad contents.txt"
    label=Mark's USB Drive
    icon=shell32.dll,12

    I’m not sure if the open command is doing anything (right click on the device and select open just lets me browse the contents). The action command is providing an action in bold at the top of the right-click menu). The shellexecute command is what happens if I double-click on the drive icon. The label is the lable shown in Explorer and the icon is a chip.

    Still no AutoPlay though… and I can see why that would be disabled as a security measure.

    Mark

  16. Mark Wilson avatar

    I’ve been looking at a USB stick I was given by Microsoft which does autoplay an application. I has two partitions – one is formatted as CDFS and if I explore that, there is an autorun.inf file, and some executable files (a Flash application, playmedia.exe, autosvr.exe and loader.exe). The autorun.inf contains the following:

    [autorun]
    OPEN=loader.exe
    CLIENT_FILE=flashapplication.exe

    The executables don’t seem to contain any information about their origin (but I hope they’re safe as I got this USB stick from a Microsoft Careers event); however loader.exe is obviously some sort of loader for the Flash application.

    The second partition is a plain old FAT disk and just contains an application called FlashDiskManager.

    Not sure if this information is of use to anyone…

    Mark

  17. inoesomestuff avatar
    inoesomestuff

    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…

  18. Mana avatar
    Mana

    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

  19. Mark Wilson avatar

    Mana – the entire contents of my autorun.inf can be seen in comment 15.

  20. Tom avatar
    Tom

    [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…

  21. o. tempora avatar
    o. tempora

    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

  22. Aires avatar
    Aires

    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.

  23. Mr Jose Cuervo avatar
    Mr Jose Cuervo

    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

  24. Sven avatar
    Sven

    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. http://www.google.com site?

    Thanks a lot for help.

  25. Sven avatar
    Sven

    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?

  26. Aires avatar
    Aires

    Bob I’m definitely interested – please post some additional info.

  27. Chris avatar

    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

  28. Mark Wilson avatar

    Thanks for the explaination Chris. I think things have moved on a bit since I wrote this 3 and a half years ago though… the choice of memory sticks was a lot more limited then.

  29. Mike Metcalf avatar
    Mike Metcalf

    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

  30. divicme avatar
    divicme

    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 !

  31. mojoo avatar
    mojoo

    How to make U3 Autorun without window opening?

    I created advertisment . And i want to Auto Run U3. But haveing problem.Please be advice.

    Upon inserting the U3-enabled flash drive into a Win XP machine or any other, I’m getting the message: “This disk or device contains more than one type of content. What would you want Windows to do?”,

    The U3 autorun application launches normally, but the above message window does not close. Is there any way to suppress this message from occurring?

    I am useing this code in autorun file.
    [autorun]
    action=zee Systems Open Program
    label=zee Systems
    icon=\graphics\logo.ico
    open=zeee_Systems.exe
    shell\open\command=zeee_Systems.exe

    Popup window image link
    http://www.von-phone.com/prodimages/skypemate/p1m-autorun.png

  32. anomonuyus avatar

    I have an idea, but I don’t think it’s going to work. Can we somehow command the USB drive to stimulate a CD, which opens autorun on the Flash Drive?

  33. Mark Wilson avatar

    @Anonymous – yes, you can – I’m not sure what the software solution is but I’ve seen it done… see comment 16 above.

  34. Jim Stroband avatar
    Jim Stroband

    I think I found the solution. First I downloaded ‘AutoRun USB 1.0’ and ‘APO Usb Autorun 1.5.’ Both of them are pretty easy to configure. They both have options to schedule backups and restore . They both work flawless. Actually I think I found the solution. Finally.

  35. ali avatar
    ali

    how to run autoplay file on windows 2000

  36. Mark Wilson avatar

    Jim Stroband (comment 34) has dropped me an e-mail to say that he has found the answer…

    “After reading your entire blog I crawled back in the web and after a few hours (and testing) I found a working solution. Actually I found 2, but one works best for me.

    Basically, after inserting a flash drive into a pc, an executable (I was looking for a backup solution) starts after a given time and does what it has to do.

    Three Files needed: a batch (autoexec.cmd), exe (autorun.exe) and an inf (autorun.inf).

    Program used: AutoRun USB 1.0 from ToroSoft Software.”

  37. supr avatar
    supr

    Any idea where one can download or buy Autorun USB 1.0?

  38.  avatar
    Anonymous

    I just found the Autorun program at:
    http://www.simtel.net/product.php%5Bid%5D84921%5BSiteID%5Dfilebasket

    Seems that the developer has removed it from his site. I’m downloading the program, but I don’t think I’m going to use it as I am too concerned about the apparent security risks.

  39. Nnyan avatar
    Nnyan

    I have a 16GB usb stick that I needed to encrypt (using TrueCrypt) but I did not want to mess around with mounting this each time I wanted to use it. So I used the TrueCrypt traveler option to create the proper autorun.inf file and move the required files onto the USB drive.

    I then used TWEAKUI (My Computer > AutoPlay > Handlers) to create a new default action (just named mine TrueCrypt Automount Volume) for mixed media. I then went into the drives default autoplay action (under drive properties) and selected mixed content and my custom action.

    Now when I plug in my drive I don’t get the windows dialog box asking me what I want to do, my volumes are automatically mounted.

  40. CaptainMorgan avatar

    AutoRun USB 1.0′ and ‘APO Usb Autorun 1.5 need to be preinstalled on a users PC before it will auto run.

    I’ve installed and tried both, they work but only solves half the problem.

    If someone could maybe code in C++ or something I’d be willing to pay.

  41. Ann-Margret Parke avatar

    Thank you so much – I renamed the icon I used on my presentation usb to “happy” in homage to your helpful coding! Again, thank you!

  42. JD avatar
    JD

    Hey Mark,
    I don’t know if you’re still watching this thread, but I figured out how to autorun a program from a usb drive without a prompt in windows XP.

    [Autorun]
    UseAutoPlay=1
    shellexecute=/*yourscript.hta*/

    I know it’s been years, but I’m actually working this issue to understand the autorun virus and how best to combat it for my company. Mind you it won’t work in windows 7 as Windows 7 disables the USB ports from using autorun.inf files. A key thing to remember is that your autorun file must have the file name Autorun.inf or it won’t work as well. Hope this is helpful to you or anyone else still running xp that need autoexecute a program when a thumbdrive is inserted.

  43. JD avatar
    JD

    To clarify the /* and */ are just comments don’t include that in the autorun script. That’s my fault. it should look like this

    [autorun]
    UseAutoPlay=1
    shellexecute=yourscript.hta

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.