Can a script automatically copy or extract files when a disc is inserted?

August 29, 2026 3 answers
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

AmberLattice6
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
CopperVale7
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
QuietHarbor18
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