There's a little known Media Center 15 feature to switch default sound devices on Vista and Windows 7. It might work faster than your script.
Run MC15.exe /SoundcardSwitch to get instructions.
This was added to Media Center 14.0.37 (07/21/2009):
NEW: Added new command /SoundcardSwitch to the launcher (MC14.exe) to allow changing the default soundcard on Windows Vista and Windows 7.
This works VERY well! After playing around with it I was able to write a batch file that switches the audio to HDMI, runs MC and on MC exit switches audio back to the sound card.
Here's the particulars if anybody wants to try it:
I'm running MC 15.0.87 on Windows 7 x64 Home Premium.
There's an MC15.exe in the Windows\System32 directory. The start /wait command won't work with this particular .exe, so it needs to be tricked. When I installed MC15 it created a shortcut on the desktop that goes through the full path - C:\Program Files (x86)\J River\Media Center 15\Media Center 15.exe. I copied the shortcut into Windows\System32 and renamed it MC15.LNK (the DOS batch language can't handle long file names).
I created a file called MC15.BAT in Windows/System32. It's only 3 commands:
MC15.exe /SoundcardSwitch Defaultbyindex:0
start "MC15" /wait MC15.LNK
MC15.exe /SoundcardSwitch Defaultbyindex:1
I have 2 sound devices. The first device in the list (right click the speaker icon in the tray, pick playback devices for the list) is the "ATI HDMI Output" the other device is "Speakers" which is the built in sound card. 0 selects HDMI; 1 selects speakers.
I then made a shortcut to the batch file on the desktop and assigned F9 to start it so it will run from my Harmony One.
So far this is working great. Any batch/script wizards that would like to improve it please feel free.
Thanks Matt for the great tip!