I was in need of a script that could change my output device between my speakers and my headphone because I do need to change between them quite often and going trough the GUI was starting to become annoying.

After consulting this question on stack overflow, I found out about Nircmd, a little piece of software that adds lots of useful fonctionnalities, among them, the one that I need.

I ended up making two batch files

setSpeakersAsOutput.bat :

nircmd.exe setdefaultsounddevice "Speakers"

setHeadPhoneAsOutput.bat :

nircmd.exe setdefaultsounddevice "EarForce X11"

I added nircmd.exe to my path. The two commands work when I execute them from a command line and it also works when I execute the ".bat" files from my file explorer but when I map the execution to a keyboard macro via my Razer Synapse software, it doesn't work. I see the CMD pop up for a second and close, like expected, but it doesn't change the settings.

My only hypothesis is that executing those scripts require administrative previleges and consequently, they can't be launched by a software. Even if this is the problem, I have no idea how to solve it.

Any help would be appreciated!

I run

  • Windows 8.1
  • I use Razer Synapse to control my Razer BlackWidow Chroma keyboard
  • Did you check if you get an error for this? Add pause as the last command to the batch to get the commandline to stay open and wait for a key press. Personally I'm using AudioSwitch which is working well for me. I haven't tried the hotkeys it's builtin though. If you want to run the batch as administrator you will have to use runas (probably). See also: How to code a BAT file to always run as admin mode? – Seth Dec 3 '16 at 21:56
  • I added pause at the end of my file and I indeed got an error. 'nircmd is not recognized as an internal command'. When I said that I had added nircmd to my path, I only did it in my user PATH variable. After seeing this error, I added it to my System Path variable but it is still not working. – Gaboik1 Dec 3 '16 at 22:03
  • How did you add it to your path? You could add a cd to the correct directory on the first line of your script. Don't forget to include /d if it resides on a different drive. – Seth Dec 4 '16 at 21:03

This is supposed to be a comment, but since I have to earn reputation from scratch on every site ....

As an alternative, you could add links to the scripts on your windows desktop and assign those keyboard shortcuts. This would make the batch files being called like you doubleclicking them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.