Lazycoder

1May/0616

Enabling autorun for a USB flash drive.

I'm a big fan of USB flash drives.. I first heard about the U3 flash drives some time ago, seems like it was pre-baby so at least last fall. I liked the idea of being able to sync desktop settings to my usb drive and have them applied when I plug into another system. I'm considering picking up one of the U3 compatible drives, but in the meantime I thought I'd see if I could come up with a poor mans solution.

The heart of the U3 niftyness is the autostarting. You plug in the USB drive, programs launch, settings are changed, all without you doing anything. Autorun has been around for years, since Windows 95 at least. To make your CD automatically start an application when you insert it, you create a file called autorun.inf and place it in the root of the CD rom. Say you want a file called foo.exe to autorun, your autorun.inf file would look like this.

CODE:
  1. [autorun]
  2. open=foo.exe
  3. icon=foo.exe

But with XP came something called Autoplay. Autoplay scans the media and pops up it's little nag window asking you what you want to do with your new found media. Without hacking the registry, you can't change this behavior. Some newer USB drives support autorun insertion. Out of the 5 drives I have, none of them supported it. All of them caused XP to display the Autoplay dialog. BUT you can add your own action to the Autoplay dialog box.

CODE:
  1. [autorun]
  2. action= Run Foo
  3. icon=foo.exe
  4. open=foo.exe

Which then displays in the Autoplay dialog box.
Autoplay_screenshot

For my main 512MB flash drive, I use the Pstart menu. This is a lightweight freeware menu program. It stays resident in your tray and allows you access to the menu by either right-clicking on it or opening up the full interface.

So with one click after inserting my flash drive, I have this nice menu to launch my portable applications from.
PStart_screenshot

I'll investigate some of the syncing and automatic workspace configuration options in a later post. Right now I'm looking at Migo. None of the applications on my flash drive cost me a dime. Portableapps.com has a great listing of some of the more popular portible applications, as well as a couple of portable applications suites you can download and put on your flash drive.

Share and Enjoy:
  • del.icio.us
  • DotNetKicks
  • DZone
  • Reddit
  • Digg
  • StumbleUpon
  • LinkedIn
  • Facebook
  • FriendFeed
  • HackerNews
  • Netvibes
  • Posterous
  • Tumblr
  • Twitter
Comments (16) Trackbacks (0)
  1. Cool! That’s some useful information you’re dropping. I just recently got a 1GB Cruzer Micro for my birthday. It’s really small and cool, but I don’t know what to do with it yet. ;)

    I work from home, so I don’t end up needing it on other computers often. I’ve got a great hammer here looking for some nails. Got any suggestions?

  2. I’ve got a couple that I just use for source code when I travel. Makes it easy to pass around code at meetings. I’ll also export contacts, notes, documents, etc… when I go to a client site or some kind of meeting. Although I usually use my Palm Pilot for that.

    Maybe you should get a few more and set them up in a striped RAID array?

  3. Hi there,

    Please can u tell me where you got that skin for Pstart – I love it!!

    Thanks very much

  4. Alex,

    That’s actually a custom style for Windows XP using a hacked dll. You can get some isntructions on installing the hack and using a custom style over at Phils blog.
    http://www.haacked.com/archive/2006/02/23/HowIPimpedMyDesktop.aspx

  5. Hey! Thanks for the reply Scott. Gonna check out the link now…

  6. Hi Scott, it’s me again! I’ve downloaded the patched Uxtheme and I was just wondering if you know the name of this visual style? Thanks again!

  7. Alex,

    I’m not sure. That theme appears to have left my system? I’m pretty sure I got it at deviantart.com.

  8. That’s some cool info, but are you 100% sure that you can’t run an autorun.inf off a USB drive? I’ve heard there’s a windows component that returns a value of DRIVE_FIXED that prevents windows from searching for a autorun file. Is there a way to change the return value of the function with just the USB drive( no previous PC modifications required)?

  9. I’m never 100% sure, but I believe the way the U3 USB devices get around this is by reporting themselves as a CD Device, in which case AutoPlay is ignored and the autorun.inf is executed.

    There are is a registry key that allows you to define handlers for specific USB devices ( they allow you to specify the USB device ID), but that requires at least enough security to edit the registry.

    I couldn’t find anything on changing the return drive type fof the USB drive without changing the registry. I found this site that explains the drive type enums and how they relate to the autorun functionality a little better than I did though.
    http://www.ashzfall.com/products/autorun/autorunfloppy.html

  10. Great stuff! You solved the exact problem I was trying to solve — how to launch the portable apps (TB, FF, etc.) from a thumbdrive.

    Sadly, it doesn’t work for me though. When I try to launch my app from the autoplay menu I get an “access is denied, E:\” error. Since it’s parsing the autorun.inf and displaying the action, icon and label correctly I can’t fathom what it’s complaining about. Any ideas?

    [autorun]
    action=Start ThunderbirdPortable
    icon=\ThunderbirdPortable\ThunderbirdPortable.exe
    open=\ThunderbirdPortable\ThunderbirdPortable.exe
    label=Portable Internet

  11. I’m not sure, I’ve never gotten that error when using autorun.inf. Some simple things to check.
    1) Is the write-protect tab set on the USB drive?
    2) If you don’t control the machine, does the admin have access to USB devices turned off?
    3) Are any of the files that thunderbird uses or writes to set to read-only?

  12. how can i autorun a batch file without the dialog box of windows. simple insert and autorun and thats it ?? any one knows how this can be done? i have the inf file the batch but i wan the computer to automaticaly run the batch without prompting the user to open files cancel or run , just running the batch file thanks

  13. Bob,
    You will find it should work if you write the file paths like so:

    [autorun]
    action=Start ThunderbirdPortable
    icon=”ThunderbirdPortable\ThunderbirdPortable.exe”
    open=”ThunderbirdPortable\ThunderbirdPortable.exe”
    label=Portable Internet

    I was having the same problem and this worked a treat.

  14. Hi Scott. I happened upon your post like a year after you’d made it! Hope I can still get a little help…
    I got your suggestion to work just fine, but the autoplay pop-up only displays the very first program option (I placed multiple options following your “action” then “open” code lines but nothing displays past the first option).
    Can you suggest anything more?
    Thanks a lot! – Rene

  15. I have Windows Vista and Windows XP Machines.
    I have tried several times.
    Here is my Autorun INF file.
    [autorun]
    OPEN=Q:
    ICON=\Icon\Flashdrive.ico
    ACTION=USB Flashdrive

    IT does not work.

    I want to:
    1. Display my drive icon in “my computer”. (Flashdrive.ico)
    2 To have the drive open up. (displaying the flashdrive’s contents)
    3. To open the Autoplay dialog box.

    I am no programmer. Can anyone help me write this Autorun.inf file ?

    mrgcav@gmail.com

  16. I was referring to a USB flashdrive in the previous post.
    MRGCAV@Gmail.com


Leave a comment


No trackbacks yet.