How can I programmatically attach/detach displays in Windows 10? - windows

I'm wondering if there's a good way to automate changing my display configuration in Windows 10?
I have 3 monitors attached, and I find myself wanting to configure my system in one of 3 ways:
All monitors set up to extend the desktop.
Only my central (largest) monitor enabled, others both disabled.
Only my right-most monitor enabled, others both disabled (I think hook up a spare HDMI cable on my center monitor to my laptop, and the monitor automatically switches to that input).
Manually, this involves opening the Display Settings panel, selecting the monitors, and either marking them as "Disconnected" or "Extend desktop on this display".
Is there some nice, scripting-friendly way to do this? I'm more comfortable doing this sorta thing on Linux, where I'd whip up a quick shell script to call the xrandr command a few times, or something like that...

Related

Windows script to run at shutdown

i have been trying to get a windows startup/shutdown sound to play, i couldn't get the sounds to play so i asked on Microsoft, here is the link https://answers.microsoft.com/en-us/windows/forum/all/cannot-change-windows-start-up-sound/8bbcb0a0-1402-4f1e-b080-9c8d526bc205
and i was told that its not possible. well too bad because i am not going to stop there, so i went to local group policy editor on windows 10 where you can choose scripts to run during shutdown and start up. i then wrote a very small PowerShell command with the file name of "shutdown.ps1" the code inside of shutdown.ps1 is
start "C:\Windows\System32\GroupPolicy\Machine\Scripts\Shutdown\TADA.wav"
this file is located in the C:\Windows\System32\GroupPolicy\Machine\Scripts\Shutdown directory along with the TADA.wav file that it plays when it shuts down.
now the issue i am having is that when windows is shutting down, its ending all processes so it does not play the sound. what can i do to change that?
I'm pretty new to all of this and am very grateful for any input you can give.
thanks in advance,
Devin
From How to Change the Windows 10 Logoff, Logon, and Shutdown Sounds in Windows 10:
...
While you can still customize what sounds sounds play for most OS events, Windows 10 hid shut down, logoff, and logon from view. They’re still around, though. You just need to make a few mild changes in the Windows Registry to get them back.
Add the Actions Back to the Sound Control Panel by Editing the Registry
To add the shutdown, logoff, and logon actions back to the menu in the Sound Control Panel app, you just need to make a few little tweaks in the Windows Registry.
...
Open the Registry Editor by hitting Start and typing “regedit.” Press Enter to open Registry Editor and then give it permission to make changes to your PC.
In the Registry Editor, use the left sidebar to navigate to the following key:
HKEY_CURRENT_USER\AppEvents\EventLabels
You’re going to be making one small change in each of three different subkeys inside that EventLabels key. First, we’ll tackle the shutdown sound or, as Windows likes to call it, System Exit. Under the EventLabels key on the left side of Registry Editor, select the SystemExit subkey. On the right side, double-click the ExcludeFromCPL value.
Note that by default, the value is 1, meaning that the action is excluded from the Control Panel. Change the value to 0 and then click “OK.”
Next, you’re going to make exactly the same change in two other subkeys inside the EventLabels key: WindowsLogoff and WindowsLogon. Head into each of those folders, open the ExcludeFromCPL value inside, and change the value from 1 to 0.
No need to restart Windows. You can go ahead and test your changes right away. Open up the Sound Control Panel app by right-clicking the speaker icon in your Notification Area and selecting “Sounds.” 1
You should now see the new actions (Exit Windows, Windows Logoff, and Windows Logon) available in the selection window and you can assign whatever sounds you like to those actions.
If, for whatever reason, you want to hide those actions from the Control Panel again, just head back into Registry Editor and change each of those ExcludeFromCPL values back to 1.
1: On my machine, to get to the Sounds control panel, I had to go into the Settings, choose "Personalization", then "Themes", then `Sounds".
UPDATE:
And indeed, all three sound events show up in my Sounds control panel once I re-enable them in the Registry. However, I tried assigning audio files to them, and although Windows remembered the assignments, nothing played when invoking those actions.
So, I guess the playback functionality is simply not implemented for those events anymore. This seems to be confirmed in your discussion with a Microsoft Insider on answers.microsoft.com (with an 89% upvote rate of 143K replies, I would think he knows what he's talking about):
In Windows 10 there is no way to change the Windows Startup Sound, that sound is set permanently in a DLL in Windows, it is not an audio file like the other system sounds, and even when you turn on the Startup sound on that dialog, sometimes the startup sound will play and other times it will not, this is a known bug in Windows 10, which seems to have been fixed in Windows 11
Windows10 does not support a shutdown sound like previous versions of Windows, you wil find many methods posted online, sadly, none of them work.

Changing screen settings in windows 10 with one click

I use three screens on my windows 10 desktop. The main screen is 1920x1200. My laptop has 1920x1080 on its only screen. I remote control my desktop from my laptop, and I change the display settings to disable the two other screens and set the resolution of my main screen to match that of my laptop. It's somewhat tedious to change those settings, so I am looking for a way to change my display settings all at once.
Essentially I wish to have two profiles: 1 for regular use, and 2 for remote control. As far as I have researched, one cannot change display settings in windows 10 from the command line, so a simple bat file is not possible.
What is a way of achieving this switch with as few clicks as possible?
Maybe you could use PowerShell with the cmdlet Set-DisplayResolution.
The documentation about this cmdlet you can find here

Detect when a user switches windows

I'm curious to know if this is possible, I want to know when a window loses focus.
I know in linux it can all be seen with xev (perhaps multiple sessions monitoring all the windows), but I need a solution in Windows.
A VM running windows in seamless mode does not help - since all internal windows are considered the 'virtualbox window', xev does not pick up internal activity.
Is there a hook to do this? Are there any other ways? I can't count on the user using alt-tab, some may click to change windows.

Use a separate desktop on a external monitor?

For my workflow, I like to have multiple desktops. One for a browser, another for some sort of editor and another for a full screen terminal.
When I connect an external monitor though. It doesn't work quite how I would like.
If I place a window on my external monitor (like my music player or something). Then I switch desktops to view my editor. My external monitor also changes desktops.
Also if I use expose, My external monitor also goes into expose mode.
Kinda annoying.
Is there anyway (possibly using 3rd party tools). To keep the two monitors seperate an have two dedicated work areas/desktops?
I have this same issue. I like to keep different IDE's open on each desktop and use my external monitor as a 'common' desktop to hold reference material, etc.
I have been able to simulate it by setting certain applications to 'All desktops' but it would be great if it was window based and automatic. That way one could drag a window to the external monitor and have it stick to all desktops and drag it back and have it stick to the current desktop.

X11 unable to maximize applications when no window manager is used

We have a Linux based system that does not use a Window manager. When we start certain applications (for instance Firefox) from a terminal window (e.g. Firefox &) we find that no matter what we do, we can't get the application to display full screen.
If we run xrandr, it shows the default resolution is 1280x1024, but when we try to maximize Firefox (by pressing F11) the application is only sized to 1203x650.
Another application that seems to have the same problem is the evince PDF reader.
Our application is not configured to run a window manager (and we don't want to add one), so I'm wondering if there is something else that we can do to get these applications to render full screen.
Thanks...
Although you don't want to use a window manager, you might need to use a window manager.
I haven't dug into the X server sources around this, so I can't definitively say X requires a window manager to run properly. But as somebody who writes X client code, and hacks the X server, on minimalist embedded devices with small screens, low CPU power and no GPU... let's just say, all the major players in that space use one, and have good reasons for it.
If you want to avoid chewing up a lot of disk space, RAM or CPU power doing window management, you should check out matchbox. It's a low-footprint window manager designed to meet those criteria, and it's what many folks in that minimalist embedded space are using. My employer uses it on cell phones, configured so that only one app at a time is visible to the user, and the foreground app takes up the whole screen with no window borders. But you can use it other ways, too - Nokia uses it for their Maemo-based network tablets.
You could use xwit(1) to forcibly resize and place the windows. But as as far as I know, X11 in itself does not have the concept of a "maximized" window; the very idea is only added by most window managers and/or applications (like Firefox).
Does passing the "-geometry=1280x1024+0+0" option to Firefox help?
Oh, also... if you don't explicitly set a window manager, you might be unexpectedly falling back to the default X11 window manager. If you're not absolutely positive there's no window manager, you should check into this possibility.

Resources