I'm using a PC with a 22" inch display and it's also connected to 40" inch LED TV (as a second/Extended) Display.
Usually I let my son play PC games on the TV, so I have to change the display to TV as primary/main Display as well as audio output I have to set it to HDMI Audio, and once he finished playing I have to return it back to the PC Display.
So I thought of doing that in command prompt but unfortunately I couldn't able to do so neither for monitor/display or audio, so of course googled that where I found interesting apps that can change the Audio or the Display but not both, so I filled the gap with autoit along the Apps Display Changer II and AudioEndPointController. And here is how:
1 - Changing Audio Playback by Code/Command PromptFirst change Audio Playback device, which is easy for non hdmi cause HDMI -for some reason- its name/number can be changed by the OS (Windows) where it can be LG TV-4 (NVIDIA High Definition Audio) or LG-SBAR-3 (NVIDIA High Definition Audio) etc ..
And All refer to the same HDMI Port where the common name is NVIDIA High Definition Audio, where this is solved using the open source app AudioEndPointController which returns list of audio device followed by a number like
Audio Device 0: LG-SBAR-4 (NVIDIA High Definition Audio)So to make it dynamic with HDMI output we use the following code:
Audio Device 1: Speakers (2- High Definition Audio Device)
Audio Device 2: Digital Audio (S/PDIF) (2- High Definition Audio Device)
Dim $syspath = "E:\MyApps\AudioEndPointController\Release\EndPointController.exe"
$DirCmd = Run(@ComSpec & " /c "&$syspath, "C:\", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)
$ResponseText &= StdoutRead($DirCmd)
If @error Then ExitLoop
Local $NvidiaHDMI = StringRegExp($ResponseText, '.*?NVIDIA', $STR_REGEXPARRAYGLOBALMATCH)
if UBound($NvidiaHDMI) >= 1 Then
$playbackID = StringRegExp($NvidiaHDMI, '\d+:', $STR_REGEXPARRAYGLOBALMATCH)
$playbackID = StringReplace($playbackID,":","")
$DirCmd = Run(@ComSpec & " /c "&$syspath& ' '& $playbackID, "C:\", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)
2 - Changing the Primary Display by Code/Command PromptNow we use Display Changer to get the settings for the primary display where you want to change later. the beauty of the Display Changer that it can directly get the current properties/settings of the display connected and save it to xml format (with -create option like E:\DC\dc2.exe -create="tv.xml" check examples here)
3 - Putting things togetherThe final code needed to change the display And Audio can be as the following:
cd "E:\DC"Once you want to change back the primary display to the PC:
Autoit Sript (v3)
Display Changer II App