How to switch displays with Node RED on Windows 10?

Hi guys!

I'm trying to automate some things from my HA dashboard. This time I want to start the TV, switch the input to HDMIx, start the PC and switch the PC display output to the TV.

Everything works except one thing...
With the command "DisplaySwitch.exe /external" I can switch my display output from the unprivileged Windows command line (cmd).
But if I try to use the same command inside a Node RED (on Windows) exec block, nothing happens. I also tried "C:\Windows\System32\DisplaySwitch.exe /external", but same result.
Exit code is always 0, unless i forcefully put in some garbage.

Any ideas why this isn't working?

Node Red is started via task scheduler using my user account.

Thanks a lot!

edit: I tried to start chrome via exec and still nothing happens. But I can observe chrome processes in the task manager, which are running with my user. In task manager they look like a usual chrome window, just with the difference that I can not see them...

hi .. what if you try to prepend cmd in the command
cmd DisplaySwitch.exe /external

[edit]
seems to be executing for me on my windows system
i dont have a second monitor but it seems to trigger the command

A pid will be displayed within node red, but I don't even see the chrome background processes if I try this with the start chrome command.

I discovered that this must have to do with how I start node red in the task scheduler. If I use "run whether user is logged on or not" it is not working, if I run it only if the user is logged in, it works! But it shows an ugly cmd window on the screen.

How are you running Node-RED. If you start it as a service it probably doesn't have the same user context.

You might want to try something like this nirsoft tool: Enable/disable/configure multiple monitors on Windows (nirsoft.net) - his utilities are always good.

I have a Python library that lets me change monitor brightness that i run twice a day - bright for working and low for evenings. But with 3 screens attached, I don't need to mess with other settings.

We crossed posts I think. You can always give Node-RED startup your user credentials when starting before login. There are also ways to get rid of the cmd window popup but it is rather arcane and I can never remember the sequence.

ok .. running Node-red when a user is not logged in defeats the purpose of switching screens :innocent:
since the second screen output is not going to be showing anything or even be able to switch (as you experienced)

maybe change the way of how Node-red autostarts and have it start when you are logged in ?
this is what i use on my Windows system.

  1. Create a batch file on the Desktop RunNodeRed.bat
  2. Edit it and add the command node-red
  3. right click the file and select Send to > Desktop (create shortcut)
  4. Right click the shortcut and go to Properties and choose Run : Minimized (that should solve the problem of having it open taking up space on the screen)
  5. Windows key + R -> Open the Run window and type : shell:startup
  6. Drag the shortcut to the folder to autostart node-red when logged in

Thank you!
I got it running and it was easier than expected. I think you headed in the same direction @UnborN
All I had to do was to switch to "only if user is logged in" and set the trigger to "on login" of that particular user (which is me) inside the task scheduler.
I expected, that after a system reboot or in lock screen, I cannot use node red, because I'm not logged in (yet). But I was wrong. It seems that Windows already logs in at system startup and only kicks you out if you forcefully switch the user or log out the user.
So my use case is totally working now and I can switch displays even without the necessity of a login :wink:

Thanks a lot!

Not quite what I am doing. But fun tool, which might be handy for another task. But one thing after another :wink:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.