frgnca / AudioDeviceCmdlets

AudioDeviceCmdlets is a suite of PowerShell Cmdlets to control audio devices on Windows
MIT License
737 stars 92 forks source link

Get-AudioDevice -List, error when disabled device present #35

Closed semce2 closed 2 years ago

semce2 commented 4 years ago

Maybe I did something wrong but this doesn't work for me. I get : Element not found. (Exception from HRESULT: 0x80070490). FullyQualifiedErrorId: System.Runtime.InteropServices.COMException,AudioDeviceCmdlets.GetAudioDevice.

cebaa commented 4 years ago

Agreed:

> Get-AudioDevice -List
Get-AudioDevice : Element not found. (Exception from HRESULT: 0x80070490)
At line:1 char:1
+ Get-AudioDevice -List
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-AudioDevice], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,AudioDeviceCmdlets.GetAudioDevice

Not sure how to get more information / troubleshoot further, @frgnca any pointers?

frgnca commented 4 years ago

Never seen this before. What is the output of say Get-AudioDevice -Index 1

Does it give a different error message?

cebaa commented 4 years ago

@frgnca

No, same:

> Get-AudioDevice -Index 1
Get-AudioDevice : Element not found. (Exception from HRESULT: 0x80070490)
At line:1 char:1
+ Get-AudioDevice -Index 1
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-AudioDevice], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,AudioDeviceCmdlets.GetAudioDevice

One more detail that I just become aware of. I have multiple audio devices. The above fails only when issued against a non-default audio device. It succeeds when issued against a default device. I've tested by changing all combinations.

This is with AudioDeviceCmdlets 3.0.0.4 by the way.

TheEngineerGuy commented 3 years ago

Same issue.

As described above, all switch parameters are working, other than List.

> Get-AudioDevice -List
Get-AudioDevice : Element not found. (Exception from HRESULT: 0x80070490)
At line:1 char:1
+ Get-AudioDevice -List
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-AudioDevice], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,AudioDeviceCmdlets.GetAudioDevice

In regards to your question @frgnca , I don't have an active device on Index 1, but if I look for 3, I get a result as expected.

>Get-AudioDevice -Index 3

Index   : 3
Default : True
Type    : Playback
Name    : Speakers (Realtek High Definition Audio)
ID      : {0.0.0.00000000}.{94f04e23-d7a2-485e-bd3b-35debef6ba0e}
Device  : CoreAudioApi.MMDevice

I have re-installed the module as well. Just to make sure that it wasn't an import issue.

> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     3.0.0.0    AudioDeviceCmdlets                  {Get-AudioDevice, Set-AudioDevice, Write-AudioDevice}

Kindly assist.

TheEngineerGuy commented 3 years ago

Performed some additional tests.

If I disable all devices, leaving only the active device enabled. I get the result. But the moment any other device gets enabled, it stops working again.

> Get-AudioDevice -List

Index   : 1
Default : True
Type    : Playback
Name    : Speakers (Realtek High Definition Audio)
ID      : {0.0.0.00000000}.{94f04e23-d7a2-485e-bd3b-35debef6ba0e}
Device  : CoreAudioApi.MMDevice

Another interesting finding, if all devices above the Default device are disabled and the ones below the default device are enabled, the list works till it hits the first non-default device.

Get-AudioDevice -List

Index   : 1
Default : True
Type    : Playback
Name    : Speakers (Realtek High Definition Audio)
ID      : {0.0.0.00000000}.{94f04e23-d7a2-485e-bd3b-35debef6ba0e}
Device  : CoreAudioApi.MMDevice

Get-AudioDevice : Element not found. (Exception from HRESULT: 0x80070490)
At line:1 char:1
+ Get-AudioDevice -List
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-AudioDevice], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,AudioDeviceCmdlets.GetAudioDevice

To me, it seems that (possibly after the new windows update) non-default devices are no longer providing an element of data required to populate this list, which makes the query to stop on first non-default device, and stop recursing through the rest of the list.

What do you think @frgnca ?

costafrancesco94 commented 3 years ago

I'm also affected by this bug, I installed the dll only with Install-Module -Name AudioDeviceCmdlets and I confirm I can see the device with Get-AudioDevice -Index 2 and I can set the audio playback with Set-AudioDevice -PlaybackVolume 50.

I cannot exec Set-AudioDevice 2 -PlaybackVolume 50 nor Set-AudioDevice "{...}" -PlaybackVolume 50 nor with Set-AudioDevice (Get-AudioDevice -Index 2) -PlaybackVolume 50 but I don't know if the behaviour is intentional. They all gave to me

Set-AudioDevice : Impossibile trovare un parametro posizionale che accetta l'argomento <whatever>
+ CategoryInfo          : InvalidArgument: (:) [Set-AudioDevice], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,AudioDeviceCmdlets.SetAudioDevice
snowmountainer commented 3 years ago

I could see the same error. Personally, I suspect that the error only occurs on computers with newer hardware.

TheEngineerGuy commented 3 years ago

I could see the same error. Personally, I suspect that the error only occurs on computers with newer hardware.

This has nothing to do with newer hardware. My PC is Haswell 4790k from 2015. I found exactly what causes the issue. When Mic is connected issue disappears, when mic is disconnected issue appears.

As posted in my previous message, latest windows update removes certain details from disconnected devices that this query is looking for. So, instead of gracefully moving to the next device, this query just crashes.

frgnca commented 2 years ago

@TheEngineerGuy

To me, it seems that (possibly after the new windows update) non-default devices are no longer providing an element of data required to populate this list, which makes the query to stop on first non-default device, and stop recursing through the rest of the list.

Here is where the error is probably occuring https://github.com/frgnca/AudioDeviceCmdlets/blob/3d33a5bb5de726d828ad9a2419bb8446e376e2f5/SOURCE/AudioDeviceCmdlets.cs#L163-L177

[...] latest windows update removes certain details from disconnected devices that this query is looking for. So, instead of gracefully moving to the next device, this query just crashes.

Hopefuly my goal of adding support for disabled/disconnected AudioDevice will bypass this problem.

TheEngineerGuy commented 2 years ago

Good find. I think you are correct. It should bypass the issue when there is something in 'recoding device' list, even if it is disabled or disconnected.

Even before this condition we could branch out the 'if', to execute 'iff' there is a device in default recording device list. If there is a default device execute as is, and if not execute modified conditions without recording device conditions. Just a thought, I leave it to you how you think it would be best.

Rochkiller commented 2 years ago

I just got this error when I disconnected my default recording device, just re-connected it the error is gone.

I have manually compiled "Dev v3.0.1 communicationdevice #30" and "add -ShowDisabled parameter support to List parameter (#24)". I don't try to see if this occurs with the lastest available release (3.0).

It's a shame that this wonderful tweak didn't update anymore ...

frgnca commented 2 years ago

I just want to confirm being able to replicate this bug by calling the -List parameter when there is no enabled playback device and/or no enabled recording device. I intent to fix this bug before merging #52 into the master branch.

frgnca commented 2 years ago

With the code as it is now in #52, I think the problem possibly exists in 3 places.

frgnca commented 2 years ago

Having fixed the way the List, ID, and Index parameters work, I came to the conclusion that this bug could also happen in the same way in pretty much all of the other parameters. I will continue to work on those from pull request #55

frgnca commented 2 years ago

I will continue to work on those from pull request #55

Pull request #55 having been merged into the dev_v3.1 branch, I can say that this issue will be fixed when pull request #52 is merged into the master branch.