Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question already has an answer here:

I want to run a program, say a batch file, when any USB mass storage device is connected. I also want to pass the drive letter as a parameter to this batch file.

This can perhaps be achieved using combination of event manager and task scheduler but I don't know how.
I am also open to use third party programs as long as they are free.

I actually know a software that has this capability. But I am looking for a free alternative.

PS: I am running Windows 7 x64 Ultimate

share|improve this question

marked as duplicate by Karan, Ƭᴇcʜιᴇ007, terdon, TFM, nhinkle Mar 11 '13 at 8:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
some parts are common in both questions....but that question does not have a satisfactory answer...moreover, i need to pass the drive letter as a command line argument... –  tumchaaditya Mar 11 '13 at 4:57
    
No satisfactory answer doesn't mean dupes are allowed. Also, if there's a solution for reliable detection via Event Logs, the logs should contain details about which drive letter was assigned. It should be obvious that people looking into this would want to do something with the drive (eg. copy files) when it's plugged in, for which the drive letter is a must. That bit's pretty much a given to go along with the main problem. Finally, while searching I found 3-4 more questions along the same line as yours and marked all as duplicates, so pretty sure there's an exact dupe somewhere among them. –  Karan Mar 11 '13 at 5:26
    
Also see here. It just occurred to me - instead of passing the drive letter to the batch file, the batch file itself can figure out which removable drives are connected once it is invoked. wmic logicaldisk where drivetype=2 will show all attributes, else filter like this: wmic logicaldisk where drivetype=2 get caption,description,drivetype,filesystem,volumename. devcon can also help; use devcon find *usbstor* or devcon status *usbstor*. –  Karan Mar 11 '13 at 5:56
    
@Karan although I agree that in this case there are several relevant pre-existing questions, keep in mind that a moderate degree of duplication is not inherently a bad thing. In this particular case, I do think it's a pretty exact duplicate, and an answer on the older question would meet the needs of the newer question. –  nhinkle Mar 11 '13 at 8:34

1 Answer 1

It's quite easy using EventVwr - just right click on the event and click "Attach task to this event". You just need to find the specific event you want. When I plugged an USB mass storage device it triggered the following events (under application category): 20001, 20003, 7036 and a few other less relevant. You just need to test those events against other USB devices events to avoid false positives.

share|improve this answer
    
ok..any possibility of sending drive letter as a parameter?..PS: there is event 2006 as well i guess –  tumchaaditya Mar 11 '13 at 4:58
    
Couldn't find anything about drive letter in those events. You can use Karan script (which is pretty smart) and modify it to your needs. But, I know there is a way to connect to any drive and folder with junctions. I've used it in the past to enter specific shadow volume copy, so I suppose it can be used here as well. For that you'll need to get the UNC of the USB drive, and create a Junction to it. –  EliadTech Mar 11 '13 at 9:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.