I want to automate two similar tasks on Windows. When a CD or DVD is inserted, I would like a script or program to detect it and either copy a particular file into a chosen folder or extract a compressed archive—usually a 7-Zip file—into that folder. This would be similar to an installer launched through autorun, except the goal would only be copying or decompressing files. Is this possible, and what approach would be most practical?
3 Answers
Yes, this can be done. An autorun configuration can launch a program, batch file, or PowerShell script that copies files. For 7-Zip archives, the disc would need to include either 7-Zip itself or another extraction utility, along with the appropriate command-line options. The script would also need to determine the optical drive letter rather than assuming it is always the same.
It is technically possible, but automatic file execution from discs is treated as a security risk because the same mechanism could install malware. Windows may block autorun or warn the user, and security software could flag the behavior. If you control the computer, a manually started script or a scheduled, trusted utility is generally safer and more dependable.
A more reliable approach is to listen for Windows' DBT_DEVICEARRIVAL event, which is triggered when a new disc is inserted. A small Windows program can respond to that event and then call a batch file, PowerShell script, or 7-Zip command to perform the copy or extraction.

Keep in mind that modern Windows versions restrict automatic execution from removable media, so the user may need to start the script manually or approve it.