frgnca / AudioDeviceCmdlets

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

Set-DefaultAudioDevice -Index 1 #5

Closed crazybbs closed 8 years ago

crazybbs commented 9 years ago

Hi ,

I'm unable to use the command Set-DefaultAudioDevice I tried several method

Set-DefaultAudioDevice -Index 1 Set-DefaultAudioDevice [-Index] 1

I got the index with the command Get-AudioDeviceList I got error Set-DefaultAudioDevice : object reference not set to an instance of an object.

Can you give us some examples and does it work on windows 10?

or maybe because I've a french OS?

Pls help me

cdhunt commented 9 years ago

Let me do some testing on Windows 10.

cdhunt commented 9 years ago

@crazybbs What does the output of Get-DefaultAudioDevice look like on your system?

crazybbs commented 9 years ago

Index DeviceFriendlyname Device


2         Haut-parleurs (Realtek High Definition Audio) CoreAudioApi.MMDevice

[logo] Mathieu Généreux Propriétaire mathieu@logiteck.camailto:mathieu@logiteck.ca Tél : (450) 551-0585 Fax : (450) 742-9531

De : Chris Hunt [mailto:notifications@github.com] Envoyé : 4 août 2015 10:06 À : cdhunt/WindowsAudioDevice-Powershell-Cmdlet WindowsAudioDevice-Powershell-Cmdlet@noreply.github.com Cc : crazybbs info@mathieugenereux.com Objet : Re: [WindowsAudioDevice-Powershell-Cmdlet] Set-DefaultAudioDevice -Index 1 (#5)

@crazybbshttps://github.com/crazybbs What does the output of Get-DefaultAudioDevice look like on your system?

— Reply to this email directly or view it on GitHubhttps://github.com/cdhunt/WindowsAudioDevice-Powershell-Cmdlet/issues/5#issuecomment-127623866.

cdhunt commented 9 years ago

It looks like you only have a single audio device so trying to change the default audio device won't accomplish much. I have tested Get/Set-DefaultAudioDeviceVolume in Windows 10 and it works. I do see the same behavior with Set-DefaultAudioDevice which could likely be related to changes in Windows 10 so I've flagged this issue as a bug.

crazybbs commented 9 years ago

Sorry,

I’ve several audio device with the command get-audiodevicelist. you asked me the command Get-defaultaudiodevice so it’s only the default one

I’ll check the future update thank you☺

[logo] Mathieu Généreux Propriétaire mathieu@logiteck.camailto:mathieu@logiteck.ca Tél : (450) 551-0585 Fax : (450) 742-9531

De : Chris Hunt [mailto:notifications@github.com] Envoyé : 4 août 2015 10:59 À : cdhunt/WindowsAudioDevice-Powershell-Cmdlet WindowsAudioDevice-Powershell-Cmdlet@noreply.github.com Cc : crazybbs info@mathieugenereux.com Objet : Re: [WindowsAudioDevice-Powershell-Cmdlet] Set-DefaultAudioDevice -Index 1 (#5)

It looks like you only have a single audio device so trying to change the default audio device won't accomplish much. I have tested Get/Set-DefaultAudioDeviceVolume in Windows 10 and it works. I do see the same behavior with Set-DefaultAudioDevice which could likely be related to changes in Windows 10 so I've flagged this issue as a bug.

— Reply to this email directly or view it on GitHubhttps://github.com/cdhunt/WindowsAudioDevice-Powershell-Cmdlet/issues/5#issuecomment-127641644.

naighz commented 9 years ago

i can't wait to get a fix for that :( thanks for your effort!

cdhunt commented 9 years ago

Good news is I found the source of the Null Reference exception. Unfortunately, it seems to be in accessing the win32 API. It's going to take a bit of work to figure out a solution.

crazybbs commented 9 years ago

Nice that you’ve found the problem and I’ll check for update time to time

Thank you,

[logo] Mathieu Généreux Propriétaire mathieu@logiteck.camailto:mathieu@logiteck.ca Tél : (450) 551-0585 Fax : (450) 742-9531

De : Chris Hunt [mailto:notifications@github.com] Envoyé : 9 août 2015 16:24 À : cdhunt/WindowsAudioDevice-Powershell-Cmdlet WindowsAudioDevice-Powershell-Cmdlet@noreply.github.com Cc : crazybbs info@mathieugenereux.com Objet : Re: [WindowsAudioDevice-Powershell-Cmdlet] Set-DefaultAudioDevice -Index 1 (#5)

Good news is I found the source of the Null Reference exception. Unfortunately, it seems to be in accessing the win32 API. It's going to take a bit of work to figure out a solution.

— Reply to this email directly or view it on GitHubhttps://github.com/cdhunt/WindowsAudioDevice-Powershell-Cmdlet/issues/5#issuecomment-129234806.

cgrace70 commented 9 years ago

I originally opened another "issue", but I figured I would post this here as it may be related. :)

I get the following error when I try to use the Set-DefaultAudioDevice cmdlet:

"Set-DefaultAudioDevice : Object reference not set to an instance of an object."

I can import the module without any issues. I don't seem to have any issues with any of the other cmdlets. I'm running 64-bit Windows 10 Pro (PowerShell v5). I don't have an issue on a second computer using 64-bit Windows 7 Pro (PowerShell v4). Both systems have multiple audio devices.

Please let me know if there is any other information I can provide to you.

thefirstben commented 9 years ago

Hello, First, i wanted to say great job on this, i was finally able to switch from my multiple sound devices using my phone and your powershell script which was really time saving ;)

Everything was working great on Windows 7, 8 and 8.1 but since i migrated to Windows 10 a month ago i'm having the same problem.

The Get-AudioDeviceList, Get-DefaultAudioDevice, Get-DefaultAudioDeviceVolume and Set-DefaultAudioDeviceMute all work as expected, only the Set-DefaultAudioDevice is not behaving.

I was trying to find another way around and i was wondering what you are using to change the default device (WMI Class, registry, API) ?

From what i see the API that was mostly used was from an undocumented Microsoft API (http://www.daveamenta.com/2011-05/programmatically-or-command-line-change-the-default-sound-playback-device-in-windows-7/) and that they may have removed in Windows 10.

I saw that before windows 10 we could you some registry keys. But from what i saw on windows 10 they are read-only and could only be changed by changing the owner of the keys which i don't like.

So i checked in powershell, and i managed to list the devices : Get-WmiObject -class "Win32_SoundDevice" -namespace "root\CIMV2"

But we can see that all properties of this class are read-only : get-ciminstance Win32_SoundDevice | Get-Member

Anyway i checked most properties and i do not see anything regarding default device : Get-WmiObject -class "Win32_SoundDevice" -namespace "root\CIMV2" | select *

And I don't see another WMI class managing the sound : Get-WmiObject -List | where-Object { $_.Name -like "sound" }

Do you have an idea of the name of the WMI Class managing the Default device ?

Thanks !

thefirstben commented 9 years ago

Seems like they had a somewhat similar problem on another project and corrected it : https://github.com/davkean/audio-switcher/issues/32

Maybe this can help you find a solution for us ;)

cgrace70 commented 9 years ago

Any update on the issue? Thanks.

MrTheoW commented 8 years ago

Would also love to know if there is any sight on a fix, or alternative.. would really like to use powershell to control my audio...

cdhunt commented 8 years ago

Thank you all for the interest in the project. I'm swamped with work projects at the moment. I hope to further investigate this soon.

MrTheoW commented 8 years ago

Awsome to hear... This function would mean, i won't have to reinsert my USB-Audiodevice when my wife has been using my computer. (She doesn't know how to use the audio setting) looking forward to the update :+1:

arccth commented 8 years ago

Worked fine for me on Windows 10. Thanks!