Overview
The toggle-VDD.ps1 script provides a quick way to toggle the Virtual Display Driver between enabled and disabled states. It’s a lightweight alternative to the full virtual-driver-manager.ps1 when you only need to quickly enable or disable the driver.
Features
- Simple toggle: One command to switch between enabled/disabled
- Automatic elevation: Self-elevates to Administrator privileges if needed
- Status detection: Automatically detects current state and performs opposite action
- Device search: Finds driver by friendly name with fallback options
Requirements
This script requires Administrator privileges and will automatically request elevation through UAC if not already running as Administrator.
- Virtual Display Driver must be installed
- PowerShell 5.1 or later
- Administrator privileges (auto-elevation enabled)
Parameters
This script takes no parameters. Simply run it to toggle the driver state.
Usage Examples
Basic Toggle
This will:
- If driver is enabled: Disable it
- If driver is disabled: Enable it
Run from Command Prompt
powershell.exe -ExecutionPolicy Bypass -File .\toggle-VDD.ps1
Create Desktop Shortcut
- Right-click on desktop and select “New > Shortcut”
- Enter this as the target:
powershell.exe -ExecutionPolicy Bypass -File "C:\Path\To\toggle-VDD.ps1"
- Name it “Toggle Virtual Display”
- Right-click the shortcut, select “Properties”
- Click “Advanced” and check “Run as administrator”
How It Works
1. Self-Elevation Check
The script first checks if it’s running with Administrator privileges:
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
# Re-launch with elevation
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
If not elevated:
- Script relaunches itself with UAC prompt
- Original process exits
- Elevated process continues execution
2. Device Discovery
Searches for the Virtual Display Driver device:
$device = Get-PnpDevice -Class Display -ErrorAction SilentlyContinue | Where-Object {
$_.FriendlyName -eq 'IddSampleDriver Device HDR' -or
$_.FriendlyName -eq 'Virtual Display Driver'
}
This searches for devices with either friendly name:
IddSampleDriver Device HDR (legacy name)
Virtual Display Driver (current name)
3. State Detection and Toggle
Checks the current device status and performs the opposite action:
if ($device.Status -eq 'OK') {
Write-Host "Disabling device"
$device | disable-pnpdevice -Confirm:$false
} else {
Write-Host "Enabling device"
$device | enable-pnpdevice -Confirm:$false
}
- Status = ‘OK’: Device is enabled → Disable it
- Any other status: Device is disabled or in error state → Enable it
Script Source
Here’s the complete script:
# submitted by zjoasan
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
$device = Get-PnpDevice -Class Display -ErrorAction SilentlyContinue | Where-Object {
$_.FriendlyName -eq 'IddSampleDriver Device HDR' -or
$_.FriendlyName -eq 'Virtual Display Driver'
}
if ($device) {
if ($device.Status -eq 'OK') {
Write-Host "Disabling device"
$device | disable-pnpdevice -Confirm:$false
} else {
Write-Host "Enabling device"
$device | enable-pnpdevice -Confirm:$false
}
} else {
Write-Warning "Device not found"
}
Output Messages
Success Messages
Displayed when the driver was enabled and is now being disabled.
Displayed when the driver was disabled and is now being enabled.
Warning Messages
WARNING: Device not found
Displayed when the Virtual Display Driver is not installed on the system.
Troubleshooting
Device Not Found Warning
Cause: Virtual Display Driver is not installed.
Solution:
# Install the driver first
.\virtual-driver-manager.ps1 -Action install
# Then toggle it
.\toggle-VDD.ps1
UAC Prompt Appears Every Time
This is expected behavior. The script requires Administrator privileges to enable/disable hardware devices.
Options:
- Accept the UAC prompt (recommended for security)
- Create a scheduled task that runs with elevated privileges
- Use the virtual-driver-manager.ps1 with
-Silent flag for automation
Script Doesn’t Execute
Cause: PowerShell execution policy blocks the script.
Solution:
# Run with bypass flag
powershell.exe -ExecutionPolicy Bypass -File .\toggle-VDD.ps1
# Or change execution policy (be aware of security implications)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Multiple Displays Found
If you have multiple display devices with matching names, the script will use the first match. This is typically not an issue as the Virtual Display Driver has unique friendly names.
Automation Examples
Batch File Toggle
Create toggle-vdd.bat:
@echo off
echo Toggling Virtual Display Driver...
powershell.exe -ExecutionPolicy Bypass -File "%~dp0toggle-VDD.ps1"
pause
Keyboard Shortcut
- Create a batch file as shown above
- Create a shortcut to the batch file
- Right-click shortcut → Properties
- Set “Shortcut key” (e.g., Ctrl+Alt+V)
- Set “Run” to “Minimized”
- Click “Advanced” and check “Run as administrator”
Toggle from Another Script
# Call the toggle script
& "$PSScriptRoot\toggle-VDD.ps1"
# Wait for device state to settle
Start-Sleep -Seconds 2
# Verify new state
$device = Get-PnpDevice | Where-Object { $_.FriendlyName -eq 'Virtual Display Driver' }
Write-Host "Driver is now: $($device.Status)"
Task Scheduler Integration
Create a scheduled task to toggle the driver:
$action = New-ScheduledTaskAction -Execute "powershell.exe" `
-Argument "-ExecutionPolicy Bypass -WindowStyle Hidden -File C:\Scripts\toggle-VDD.ps1"
$trigger = New-ScheduledTaskTrigger -AtLogOn
$principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -RunLevel Highest
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
Register-ScheduledTask -TaskName "Toggle VDD at Logon" `
-Action $action `
-Trigger $trigger `
-Principal $principal `
-Settings $settings
Comparison with virtual-driver-manager.ps1
| Feature | toggle-VDD.ps1 | virtual-driver-manager.ps1 |
|---|
| Toggle driver | Yes | Yes (with -Action toggle) |
| Install/Uninstall | No | Yes |
| Check status | No | Yes |
| JSON output | No | Yes |
| Silent mode | No | Yes |
| File size | ~1 KB | ~20 KB |
| Dependencies | None | Internet for install/uninstall |
| Best for | Quick toggles | Full management |
Use toggle-VDD.ps1 when:
- You only need to enable/disable the driver
- You want a simple, fast script
- You don’t need automation features
Use virtual-driver-manager.ps1 when:
- You need to install or uninstall the driver
- You want JSON output for automation
- You need status checking
- You want silent/verbose modes
Credits
Script submitted by zjoasan.