Enabling Recording Device

Brand new to powershell. I’m still going through various tutorials honestly but I’m trying to make a quick script to enable to “Stereo Mix” device in the recording tab under sound in the control panel. I feel like there should be an easy way to do this however I can’t find a way to do this in a basic vanilla Powershell. Everywhere I look is getting me to download extra things to make it work and since this is a small company project, I just need it to run standalone.

Does anyone have ideas for how to do it, or if this is even possible?

So this took much longer to look into than i thought

Initially I thought something like this should work:

Get-PnpDevice -FriendlyName '*Stereo Mix*' | Enable-PnpDevice -Confirm:$false

but no dice… maybe it would work for you. I can’t seem to get it to work (with or without admin rights) when the device is in a ‘disabled’ state. I just get a generic error. I fought with for a bit and gave up.

One other way i thought about was a reg key. One can use something like ‘regmon’ to monitor… but I figured someone probably did this before from a general device perspective. I did some digging and it seems the device ID lines up with the keys in this reg path:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\

The output of Get-PNPDevice gives some identifying info, namely DeviceID:

Get-PnpDevice -FriendlyName '*Stereo Mix*' | Select-Object -ExpandProperty DeviceID

For me this outputs:
SWD\MMDEVAPI\{0.0.1.00000000}.{A9B18BD2-0466-4251-AC78-FC1B6D4E9353}

The {A9B18BD2-0466-4251-AC78-FC1B6D4E9353 appears to be the GUID and also happens to be a subkey of the reg path above… so:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{a9b18bd2-0466-4251-ac78-fc1b6d4e9353}

In this Key, noticed there was a DeviceState DWORD value. Toying it with that key some. I found that a value of ‘1’ seems to be enabled (though if you set it in registry, the GUI isn’t going to update until you get out of it and back in).

Which leads me to a potential solution for you. First you need to go through the steps above to find the correct path to use. It’s possible it’s the same as mine, but I don’t know. Once you ahve that, you can use PowerShell to do things in the registry.

Working with registry keys - PowerShell | Microsoft Learn and Working with registry entries - PowerShell | Microsoft Learn

Getting the current value:

Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{a9b18bd2-0466-4251-ac78-fc1b6d4e9353}\' -Name DeviceState

You may need to replace the GUID as I mentioned before. and to set it:

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture\{a9b18bd2-0466-4251-ac78-fc1b6d4e9353}\' -Name DeviceState -Value 1

And on course, the issues don’t stop there :slight_smile: even though I could change it in the registry (opened as an admin) I could not via powershell with that same account (PS running as an admin). This appears to be common: Cannot set-itemproperty in registry : PowerShell (reddit.com). That thread talks about ways other people have worked around the issue. What’s strange is for me, by default, admins have the ability to set values and it definitely works in the GUI:

image

Alas, you may have to play around with it some but that technically should get you where need to be. I don’t know if it’s worth the hassle personally, but you might try to do some more googling on it.

I appreciate it. I’ll fiddle with this information some see what I can figure out. It probably won’t be worth the hassle but anything to keep the process simpler for other users.

Just to follow up with what I could find.

I would not be able to setup a script without using a thirdparty program. It appears that, as you pointed out, powershell won’t be able to run a higher level than administrator. The built in Admin account for windows is just a placeholder for functioning on safe mode.

If I understand what the user was explaining.
So if I was to setup the script it requires a passphrase. Which makes it a harder script to run on multiple systems for just a simple fix.
Regardless, this is at least a good learning experience for me. Registry functions are mostly off limits for a script to run on multiple systems due to PassPhrase and permissions.

Yeah. I mean there’s ways around this, like PSEXEC probably, but I… don’t really want to recommend that. Glad you were able to get something out of it though!

1 Like