Custom AutoPlay Documentation

Regedit automation tool

built for Windows, built with ♡ • by tomandesMSH

↓ Download latest See on GitHub →

Why is this process automated?

Adding a custom AutoPlay entry for CD/DVD drives in Windows requires manually editing multiple registry keys across different hives. Tutorials are either outdated or misleading. This tool automates the entire process - just run it and youre done.

Tutorials are useless

Most guides are outdated, incomplete, or wrong. Finding accurate info is a nightmare, since Microsoft keeps updating the registrars.

Registry is complicated

Multiple deeply nested keys across different hives. One wrong move and youre cooked.

One tool that fixes it all.

One exe, one run. All registry entries created automatically.


Features

Creating a Restore Point

Before touching anything, a Windows restore point is created so you can roll back if needed.

Registry Keys

All necessary registry keys and values are created automatically. No manual editing.

Result

Your chosen app appears as an option in the Windows DVD AutoPlay dialog.

Custom Shell Dialogue

Customize the text shown in the AutoPlay dialog. someday.

coming soon...

Multiple AutoPlay Entries

Register multiple handlers at once. You can still do this by running the program multiple times.

maybe..

How to use?

⚠️

Administrator access required. This program modifies the Windows Registry and must be run as Administrator. A restore point is created automatically before any changes.

1.

Download the exe

Download AutoPlayHandler.exe from the Releases page on GitHub.

2.

Run as Administrator

Right-click -> "Run as administrator". Required for registry access.

3.

Follow the setup

The tool guides you through selecting your app and setting it as an autoplay option.

4.

Try it out!

Insert a CD/DVD. your selected app should now appear in the AutoPlay dialog.


Built with

python winreg batch
Python 98.9% Batch 1.1%



Code Explained

The same code, just with more comments.

import os
import time
import ctypes       # used to call Windows API functions (like admin check)
import sys
import winreg       # used to read/write Windows Registry
import subprocess   # used to run external programs (the .bat file)

# ===== ADMIN CHECK =====
def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()  # asks Windows if current user is admin
    except:
        return False

if not is_admin():
    # if not admin, re-launches the script with "runas" = triggers UAC prompt
    ctypes.windll.shell32.ShellExecuteW(
        None, "runas", sys.executable, " ".join(sys.argv), None, 1
    )
    sys.exit()  # closes the non-admin instance

# ===== INTRO =====
input("...Press ENTER to continue...")  # pauses until user presses Enter

os.system("cls")  # clears the terminal

# ===== QUESTIONS =====
AppName = input("What is the name of the app...")   # e.g. "VLC"
Action  = input("What is the name of the action...") # e.g. "Open with VLC"
Path    = input("Where is the app stored?...")       # e.g. "C:/Program Files/VLC/vlc.exe"

def reg_escape(path):
    return path.replace("/", "\\")  # converts forward slashes to backslashes for registry compatibility

EscapedPath = reg_escape(Path)  # stores the corrected path

# ===== WRITE REGISTRY =====

# creates HKEY_CLASSES_ROOT\VLC.AutoPlay and sets its default value
with winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, f"{AppName}.AutoPlay") as key:
    winreg.SetValueEx(key, "", 0, winreg.REG_SZ, f"{AppName} AutoPlay")

# creates the \shell subkey and sets default to "open"
with winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, f"{AppName}.AutoPlay\\shell") as key:
    winreg.SetValueEx(key, "", 0, winreg.REG_SZ, "open")

# creates \shell\open\command — tells Windows what to actually run when AutoPlay fires
# "%1" = the drive path passed by Windows (e.g. D:\)
with winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, f"{AppName}.AutoPlay\\shell\\open\\command") as key:
    winreg.SetValueEx(key, "", 0, winreg.REG_SZ, f'"{EscapedPath}" "%1"')

# opens the PlayDVDMovieOnArrival event handler list and registers the new handler name
play_dvd_key_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\EventHandlers\PlayDVDMovieOnArrival"
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, play_dvd_key_path, 0, winreg.KEY_SET_VALUE) as key:
    winreg.SetValueEx(key, f"{AppName}Handler", 0, winreg.REG_SZ, "")  # registers e.g. "VLCHandler" as an empty string value

# creates the handler's own key under Handlers\ and fills in its 5 required values
handlers_key_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\Handlers"
with winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, f"{handlers_key_path}\\{AppName}Handler") as key:
    winreg.SetValueEx(key, "Action",      0, winreg.REG_SZ, Action)               # the label shown in AutoPlay dialog
    winreg.SetValueEx(key, "DefaultIcon", 0, winreg.REG_SZ, f"{EscapedPath},0")   # icon shown next to the action (,0 = first icon in the exe)
    winreg.SetValueEx(key, "InvokeProgID",0, winreg.REG_SZ, f"{AppName}.AutoPlay")# links back to the HKCR key we created above
    winreg.SetValueEx(key, "InvokeVerb",  0, winreg.REG_SZ, "open")               # the verb to invoke (matches \shell\open)
    winreg.SetValueEx(key, "Provider",    0, winreg.REG_SZ, AppName)              # the app name shown as provider in dialog

# runs rexplorer.bat — restarts explorer.exe so the new AutoPlay entry loads without a full reboot
subprocess.call(bat_file)