Auto run when USB plugged in

Dan1676 picture Dan1676 · Feb 26, 2012 · Viewed 10.1k times · Source

Is it possible to make a program auto run (execute) when the USB it is stored on is plugged into a computer

I don't think this is possible due to the searching I have looked at on the Internet and also the security risk such coding would have

E.g. I have a simple countdown timer (10 to 1) programmed in C++ (complied on windows), when the USB (which the .exe file is stored on) is plugged into a computer the timer will start without me executing it manually.

Answer

SoapBox picture SoapBox · Feb 26, 2012

You can create an Autorun.inf file and place it on the USB drive. Windows will read this file when the drive is connected. In the file you can specify the name of the program you'd like to run, as well as icons, etc.

You cannot force the program to run when the USB drive is inserted. That's up to the security policy of the operating system, and most will at least prompt the user "Do you want to run 'Setup.exe' from this drive?" or something like that.