Skip to main content

Overview

VBScript utilities for Windows system automation and configuration. These scripts are tested on Windows 7, 10, and 11 (x64).
VBScript is a legacy scripting language still supported in modern Windows for backward compatibility. For new projects, consider using PowerShell instead.

Prerequisites

  • Windows 7, 10, or 11 (x64)
  • Administrator privileges (for most operations)
  • Windows Script Host (WSH) enabled (enabled by default)

Available Scripts

Autorun Disable

Disable Windows AutoRun/AutoPlay functionality to enhance security. Download:
curl -o autorun.vbs https://raw.githubusercontent.com/maravento/vault/master/scripts/vbs/autorun.vbs
Usage:
  1. Download the script
  2. Right-click autorun.vbs
  3. Select “Open with” → “Microsoft Windows Based Script Host”
Or simply double-click the file.
Features:
  • Disables AutoRun for all drives
  • Disables AutoPlay for removable media
  • Registry-based configuration
  • Improves security against USB-based attacks
  • Prevents automatic execution of malware
What It Does:
Prevents automatic execution of programs when removable media (USB drives, CDs, DVDs) is inserted.Protection Against:
  • USB-based malware
  • Auto-executing viruses
  • Unwanted program launches
  • Social engineering attacks
The script modifies the following registry keys:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer
Sets:
  • NoDriveTypeAutoRun = 255 (disable all drive types)
  • NoAutorun = 1 (disable autorun)
Disables AutoRun/AutoPlay for:
  • USB flash drives
  • External hard drives
  • CD/DVD drives
  • Memory cards
  • Network drives

Script Details

How VBScript Works on Windows

VBScript files (.vbs) are executed by Windows Script Host (WSH), which provides two execution environments:
  • wscript.exe: GUI mode (default when double-clicking)
  • cscript.exe: Console mode (for command-line usage)

Execution Methods

REM Simply double-click the .vbs file
REM Runs in GUI mode using wscript.exe

Security Considerations

Important Security Notes:
  1. Review Before Execution: Always review VBScript content before running
  2. Administrator Rights: Most system modifications require admin privileges
  3. Backup Registry: Create a registry backup before running system modification scripts
  4. Test Environment: Test scripts in a non-production environment first

Why Disable AutoRun?

AutoRun/AutoPlay was a common attack vector:
  • Malware Propagation: Infected USB drives could auto-execute malware
  • Social Engineering: Attackers could disguise malware as legitimate autorun content
  • Worm Spreading: Network worms used AutoRun to spread across systems
Microsoft has disabled AutoRun by default in Windows 7 and later for removable drives, but AutoPlay may still be enabled. This script ensures both are disabled.

Advanced Usage

Running at System Startup

REM Create scheduled task to run at startup
schtasks /create /tn "Disable AutoRun" /tr "cscript C:\path\to\autorun.vbs" /sc onstart /ru System

Verifying AutoRun Status

Check if AutoRun is disabled:
REM Query registry value
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDriveTypeAutoRun
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDriveTypeAutoRun
Expected output:
NoDriveTypeAutoRun    REG_DWORD    0xff (255)

Reverting Changes

To re-enable AutoRun (not recommended):
REM Delete registry values to restore defaults
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDriveTypeAutoRun /f
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoAutorun /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDriveTypeAutoRun /f

Alternatives to VBScript

For modern Windows automation, consider:

PowerShell

Modern, powerful scripting language built into Windows
# PowerShell equivalent
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "NoDriveTypeAutoRun" -Value 255

Batch Scripts

Simple command-line scripts for basic automation
REM Batch equivalent
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDriveTypeAutoRun /t REG_DWORD /d 255 /f

Troubleshooting

Possible Causes:
  • Windows Script Host disabled
  • Antivirus blocking execution
  • File association broken
Solutions:
REM Enable Windows Script Host
reg add "HKCU\Software\Microsoft\Windows Script Host\Settings" /v Enabled /t REG_DWORD /d 1 /f

REM Check file association
assoc .vbs
ftype VBSFile
Solution:
  • Run Command Prompt as Administrator
  • Use elevated privileges
REM Right-click cmd.exe → "Run as administrator"
cscript autorun.vbs
Solution:
  • Log off and log back in
  • Restart Windows Explorer
  • Reboot the system
REM Restart Explorer
taskkill /f /im explorer.exe
start explorer.exe

Best Practices

  1. Code Review: Always review VBScript contents before execution
  2. Backup: Create system restore point before running system modification scripts
  3. Testing: Test scripts in virtual machines or test environments first
  4. Documentation: Keep notes of what scripts do and when they were run
  5. Updates: Check for script updates periodically

Additional Resources

Windows Script Host

Learn more about WSH and VBScript fundamentals

Registry Editor

Understanding Windows Registry for advanced configuration

Security Hardening

Windows security best practices and hardening guides

PowerShell Migration

Migrate from VBScript to modern PowerShell scripts

License

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND. Test scripts in a safe environment before deploying to production systems.

Build docs developers (and LLMs) love