How to extract the name of the current default audio device via cmd on win10?

13,643

Solution 1

I have not found a way to extract the name of the current audio device.

If you don't mind using PowerShell then try Get-DefaultAudioDevice from Powershell Cmdlets for manipulating Windows Audio Devices:

Basic command-line audio device control from Powershell including Nuget Package Manager Console.

Features: Set Volume and toggle Mute on the Default Playback Device. Get a list of devices and set the Default Audio Device.

...

Exposed Cmdlets

Get-DefaultAudioDevice
Get-AudioDeviceList
Set-DefaultAudioDevice [-Index] <Int>
Set-DefaultAudioDevice [-Name] <String>
Set-DefaultAudioDevice [-InputObject] <AudioDevice>
Set-DefaultAudioDeviceVolume -Volume <float>
Get-DefaultAudioDeviceVolume
Set-DefaultAudioDeviceMute <Bool>
Set-DefaultAudioDeviceMute #Toggle
Get-DefaultAudioDeviceMute
Write-DefaultAudioDeviceValue [-StreamValue]

Solution 2

You can use SoundVolumeView to dump your audio devices into a CSV file and then parse it using cut and grep:

SoundVolumeView.exe /scomma dump.csv
cut dump.csv -d',' -f1,5|grep ',Render'|cut -d',' -f1

Unfortunately it doesn’t seem to support stdout so it’s necessary to write to a file.

Column 1 contains the device name, column 5 is the column named "Default" and contains either "Render" or "Capture" (or nothing). If you have changed the column order in the GUI, you have to change the indices. Better than fixed indices would be to parse the first line looking for the column headers "Name" and "Default".

As for cut and grep, I use the programs included in Git for Windows. If you dont’t want to install Git, you could use gow. They are also included in GnuWin and GNU utilities for Win32, but those haven’t been updated for years.

Share:
13,643

Related videos on Youtube

Josef
Author by

Josef

Updated on September 18, 2022

Comments

  • Josef
    Josef almost 2 years

    I would like to write a single batch-file which toggles my default sound device, since i only use two.

    I'm already using nircmd to set the default device but I have not found a way to extract the name of the current device.

    • Dave
      Dave almost 7 years
      This may be helpful / related superuser.com/questions/1054594/…
    • Josef
      Josef almost 7 years
      @Dave Actually from this thread i got the "how to set" but not "how to get" the name of the device
    • Dave
      Dave almost 7 years
      And does entering driverquery into a cmd contain what you want?
    • Dave
      Dave almost 7 years
      Does this powershell do it? See last post social.technet.microsoft.com/Forums/windows/en-US/…
    • Josef
      Josef almost 7 years
      @Dave Ideally I want the same name which it has in sound control, because thats what nircmd expects, i will look into the script
    • Josef
      Josef almost 7 years
      Ok so its the same name, but i dont see a way to determine if it is listed as the default device.
  • Josef
    Josef almost 7 years
    This seems to do the trick, will try that out, thanks!