Skip to content

Instantly share code, notes, and snippets.

@x0rp01s0n
Last active March 13, 2025 19:39
Show Gist options
  • Save x0rp01s0n/96625babf7639b9a72d20f449615887a to your computer and use it in GitHub Desktop.
Save x0rp01s0n/96625babf7639b9a72d20f449615887a to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2023-01-18T18:19:11.4118961</Date>
<Author>NULL234\null234</Author>
<URI>\SetDefaulDeviceOnConnection</URI>
<Description>Stop annoying windows! i want to decide what stadart playback device i use.</Description>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-DriverFrameworks-UserMode/Operational"&gt;&lt;Select Path="Microsoft-Windows-DriverFrameworks-UserMode/Operational"&gt;*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0 or Level=5)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
</EventTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-2611742254-942843215-3789948414-1001</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Temp\SoundVolumeView.exe</Command>
<Arguments>/SetDefault "VB-Audio VoiceMeeter VAIO\Device\VoiceMeeter Input\Render" 0</Arguments>
</Exec>
<Exec>
<Command>C:\Temp\SoundVolumeView.exe</Command>
<Arguments>/SetDefault "VB-Audio VoiceMeeter VAIO\Device\VoiceMeeter Input\Render" 1</Arguments>
</Exec>
<Exec>
<Command>C:\Temp\SoundVolumeView.exe</Command>
<Arguments>/SetDefault "VB-Audio VoiceMeeter VAIO\Device\VoiceMeeter Input\Render" 2</Arguments>
</Exec>
</Actions>
</Task>
@tommoyang
Copy link

tommoyang commented Jun 14, 2024

For anybody in the future looking at this - Would suggest changing line 12

# Old
-      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-DriverFrameworks-UserMode/Operational"&gt;&lt;Select Path="Microsoft-Windows-DriverFrameworks-UserMode/Operational"&gt;*[System[(Level=1  or Level=2 or Level=3 or Level=4 or Level=0 or Level=5)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>

# New
+      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-Audio-UserMode/Operational"&gt;&lt;Select Path="Microsoft-Windows-Audio-UserMode/Operational"&gt;*[System[(Level=1  or Level=2 or Level=3 or Level=4 or Level=0 or Level=5)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>

Or more specifically

# Remove this
-DriverFrameworks

# Replace with this
+Audio

This makes the task trigger on audio device change, instead of driver change. I assume if you're doing this script you never want to switch off voicemeeter anyway, so it won't matter!

@void-snw
Copy link

For some reason both of these methods didn't work on my device, throws me an error number when attempting to create the task that I can't find anything about. If this happens to someone else one day, here's the two things I needed to change in the scheduled task creation window (Windows 10, up to date as of 13th March 2025):

  1. Change user account to my own
  2. Create new trigger

Begin task = On an event
Log = Microsoft-Windows-Audio/Operational
Source = Audio
Event ID = 65

If this also doesn't work for some reason, you can hopefully find the necessary information in the Event Viewer under a path that looks similar to this: Applications and Services Logs > Microsoft > Windows > Audio > Operational. Here you should find an event every time an audio device is connected or disconnected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment