开发者

Change playback device programmatically xp

开发者 https://www.devze.com 2023-01-24 07:52 出处:网络
How can i change which is the current sound card in use (xp), without going into control panel>sounds devices> choose开发者_如何学C playback device.

How can i change which is the current sound card in use (xp), without going into control panel>sounds devices> choose开发者_如何学C playback device.

any language would suffice, or batch file, just that i have to change the device for playback about 50 times a day and its a pain having to load control panel each time.

How?


To set the default sound playback device in Windows XP, you can change the value of the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Sound Mapper\Playback

Probably the easiest thing to do, given an existing configuration with all of the devices you wish to be able to select from installed, is to select each of the sound playback devices one at a time in the Sound and Audio Device Properties control panel and export the settings for this registry key to a file. So, if you had 3 sound playback devices that you wanted to be able to choose between, you would end up with 3 separate .REG files, each corresponding to one of the playback devices. Otherwise, you will have to generate the registry entry files programmatically on the fly.

Once you've generated these .REG files, simply double-clicking on one of them in Explorer will insert the information that they contain into the appropriate location in the registry, which will select the corresponding playback device. You can easily execute these registry scripts programmatically. In C#, you might use something like System.Diagnostics.Process.Start and pass the location of the .REG file that you want to take effect. Alternatively, you could write a simple batch file that silently imports the registration entries file without requiring confirmation:

@echo off
%windir%\regedit.exe /s ExternalSpeakers.reg

It goes without saying that in applying this solution and manually editing your registry, you take full responsibility for any havoc that you may wreak with your Windows installation.

(I understand that a Windows XP solution is what the asker is looking for, but for any future Googlers, note that this will NOT work with Windows Vista or later, which uses the Core Audio APIs to manage these settings instead. See this question for a solution.)

0

精彩评论

暂无评论...
验证码 换一张
取 消