Can a script automatically copy or extract files when a disc is inserted?
Asked by
MellowPine42
I'm trying to automate a simple Windows task involving an optical disc. When a CD or DVD is inserted, I'd like a file on it to be copied automatically into a specific folder. In another version, the disc would contain a compressed archiveโmostly 7-Zipโand the archive would be extracted into that destination folder instead. This would be similar to an installer using autorun, except the goal is only to copy or decompress files. Is this possible, and what kind of script or configuration would be needed?
Answers
Yes, it can be coded, but expect security software or Windows policies to flag or prevent it. Automatically launching programs and writing files as soon as a disc is inserted resembles common malware behavior. In practice, a user-confirmed script or small utility is likely to work more consistently than fully automatic autorun.
Reply to this answer
Itโs technically possible. An autorun configuration can launch a program, and that program could copy files with a batch or PowerShell script, or run a decompression utility with the appropriate arguments. Youโd need to determine the optical driveโs actual drive letter and includeโor otherwise have access toโthe extraction tool. However, automatic execution from removable media is heavily restricted in modern Windows because itโs a major malware risk, so autorun may be disabled or blocked entirely.
Reply to this answer
A more reliable approach is to watch for Windowsโ DBT_DEVICEARRIVAL device-notification event, which signals that a disc has been inserted. A small Windows program can respond to that event and then invoke a copy or extraction script. This avoids relying entirely on optical-disc autorun, though the program still needs suitable permissions and should validate the disc contents before doing anything.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions