Answered by:

Programmatically Enable/Disable a "Sound Device"

Question

I have tried several USB headsets made by two different vendors, all of which behave the same way on Windows 7 X 64 (in a way different from the way they work in Windows XP.)

On the Windows 7 systems the output (speaker) portion intermittently stops operating. This failure occurs about once every 30 to 40 minand is extremely annoying.

I have discovered that if I first disabled the device and immediately reenable it using the "Sounds" dialog proper function is restored – that is the speaker speaks!

If I can write a program that avoids opening the sound dialog, right clicking on the device, clicking disable, right clicking on the device a second time, clicking on enable and then closing the sound dialog . Not only will I save myself a lot of
time but also a great deal of annoyance/aggravation.

I am physically impaired and use Dragon NaturallySpeaking to perform many functions. If I could write a program to perform this task a simple voice command would accomplish the same thing – much to my relief.

The problem is: I have no idea what the interface is between Visual C++ and the sound devices or, for that fact, if there is one.

If some kind soul would guide me through this I would be deeply grateful. No

In order to use the sample C++ project I had to update Visual C++ from the 2008 version to the 2010. That done, I tried to build the sample but the bill did not succeed – the error message indicated that

WindowsApplicationForDrivers8.0

was missing.

Do you have any idea where I can find this package?

By the way: I really do not want to GUI for this purpose. I needed a .exe or .CMD which I can place on the Desktop and, in turn, invoke using a voice command to be executed by Dragon.

I have tried numerous syntactical variations but none of them seems to work. Any advice?
Also, I haven't a clue where the underscored line in the command output comes from – do you have any ideas about that?

the underlined text is the device instance that matches the hardware ID you passed. IIRC, there is a syntax using @ that allows you to specify the instance to enable/disable or perhaps some other commands

d -- This posting is provided "AS IS" with no warranties, and confers no rights.

On my motherboard there are two wholly independent USB controllers and I get the same failure when the device is plugged into either USB controller..

Also, you'll note that one of the "find" commands did find the device and quite certainly since I am dictating to Dragon NaturallySpeaking using the device, it is definitely plugged in. As further evidence I just disabled/enabled it using the "Sounds"
dialog.

From the above I'm fairly well convinced that your analysis is probably not correct but thank you so much for trying.

At this point I am quite certain that nothing in "Device Manager" or Devcon will do what I want to do. These two facilities can make a device disappear and, in some cases, reappear in the system.

It appears that these two capabilities operate at the device existence level rather than at the
device function level where the "Sounds" dialog operates – i.e. the level where I need to act.

Please recall that the action I want to happen is to exactly reproduce the effects of using the sound dialog to:

Visually select the appropriate "Playback" device in the GUI and right-click on it. Programmatically – this probably involves the use of an enumeration API and selecting a handle for the desired device from that enumeration.

Left click on disable. Programmatically – call the disable API with a handle found above.
Right-click again on the same device – programmatically this is probably not needed,
Left-click on enable. Programmatically call the enable API again using a handle obtained above.

The sound GUI dialog to which I refer is, in Windows 7, located in the Control Panel. Insofar as I know this dialog has no keyboard (only a mouse) interface. On the tab of interest (Playback) it presents a column of icons each representing a
sound output device on the system.

To accomplish my task: I must open the sounds dialog, position the pointer atop the CS50 icon, right-click on it which presents a context list, move the pointer to the "disable" item and left click it, reposition the pointer to the same icon, right-click
it and then left click on the "enable" item in the context list and, finally, close the dialog.

Please note that because I am seriously visually impaired (legally blind) the above is quite difficult for me to accomplish.

Perhaps spy++ can trace the above actions but that is well beyond my level of sophistication.

I asked the audio folks. the APIs the UI calls disable/enable are not public. I think your next best bet will be to use the accessibility APIs to "script" the selection, right click, click on the menu item, etc to automate this process

d -- This posting is provided "AS IS" with no warranties, and confers no rights.

My Visual C++ 2008 Express Edition would not compile the source code (it complaints about errors in stdafx.h). So, I tried to download the.exe but, for some reason, both Internet Explorer and Firefox refused to download anything but the .cpp file (i.e.
they didn't allow access to either the .CMD or the .exe file.)

In the full spirit of "No Good Deed Goes Unpunished" if you could rename the executable to something like .XEX the browser will probably allow me to download it.

On a sour note:

I find it offensive that Microsoft in its paternalism or arrogance has seen fit to hide the API call which, I am quite certain exists and, is probably the only thing done when the context menu items enable/disable are clicked. Perhaps I am too sensitive.

since it was a rar package and you say you can only get the cpp and not exe i think your av / blah blah / sandbox/ whatever is extracting the package and selectively stopping executable files from being downloaed

so instead of renaming (a non stupid sandbox /whatever shouldn't rely on extensions alone is what i believe)

i passworded the package

the password is stated below the animated png that i added to the page