Get a Pentest and security assessment of your IT network.

Cyber Security

USB AutoRun: Run Programs Automatically

TL;DR

AutoRunning programs from a USB drive is generally disabled for security reasons. However, you can achieve similar functionality using batch files and the Windows Task Scheduler or by modifying registry settings (advanced users only). This guide covers both methods.

Method 1: Using a Batch File & Task Scheduler

  1. Create a Batch File: Open Notepad and write a command to start your program. For example, to run ‘myprogram.exe’ located in the root of the USB drive:
    @echo off
    start myprogram.exe

    Save this file as ‘autorun.bat’ on your USB drive.

  2. Create a Task Scheduler Entry:
    • Press the Windows key, type “Task Scheduler”, and open it.
    • In the right pane, click “Create Basic Task…”.
    • Give the task a name (e.g., ‘USB Program Launch’) and description.
    • Choose “When I plug in this USB drive” as the trigger. You may need to select your specific USB device from the dropdown.
    • Select “Start a program” as the action.
    • In the “Program/script” field, enter ‘cmd’.
    • In the “Add arguments (optional)” field, enter ‘/c autorun.bat’ (replace ‘autorun.bat’ with your batch file name if different).
    • Click “Finish”.
  3. Test: Plug in your USB drive. The program should launch automatically.

Method 2: (Advanced) Registry Modification – Use with Caution!

Warning: Incorrect registry modifications can cause system instability. Back up your registry before proceeding.

  1. Open Registry Editor: Press the Windows key, type “regedit”, and open it.
  2. Navigate to AutoRun Keys: Go to one of these locations (depending on your Windows version):
    • HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerAutoplayHandlersEventHandlers
    • HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerAutoplayHandlersEventHandlers
  3. Create a New Key: Right-click in the right pane, select “New” -> “Key”. Name it something descriptive (e.g., ‘MyUSBProgram’).
  4. Set Values: Inside your new key:
    • Double-click “Action”. Set the value to the path of your program (e.g., ‘E:myprogram.exe’ – replace with your actual drive letter and program name).
    • Double-click “Provider”. Set the value to a descriptive name for your application.
  5. Configure Autoplay: In Registry Editor, navigate to HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesExplorerAutoplayHandlersEventHandlers and ensure that your key is enabled.
  6. Test: Plug in your USB drive. The program should launch automatically (may require confirming a prompt).

Important Considerations

  • Security Risks: AutoRun functionality can be exploited by malware. Be cautious about running programs from unknown USB drives.
  • Windows Security Settings: Modern versions of Windows often disable AutoRun for security reasons. The Task Scheduler method is generally more reliable.
  • Drive Letter Changes: If the drive letter assigned to your USB drive changes, you may need to update the batch file or registry entry accordingly.
Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation