think tank forum

technology » extend/collapse desktop script

dannyp's avatar
16 years ago
link
dannyp
dʎuuɐp
Every time I get home with icarus I have to plug in my 19" widescreen's vga cable. Extending the desktop is a pain in the ass to do manually every time. I got tired of spending my time doing it by hand in the options and just started punching the function+monitor button on the keyboard which doesn't actually extend the desktop, it just flops the output, or mirrors.

I searched around and found a way to do it using vbscript.

This utilizes the invocation of control.exe loading a windows control panel applet (*.cpl file) that loads the familiar control panel windows you normally see. In this case I'm using desk.cpl that loads the third tab which is the settings tab. If you want to look at the different control panel applets on the command-line go:

cd C:\WINDOWS\system32
dir *.cpl



Some details about them at wikipedia

if you want to run one of them:

control powercfg.cpl



It would be great if there was a way that these applets were command-line driven programs as well as graphical. Since that's not the case I think I must do it this way. I made two text files named in the following ways:

1. extend.vbs

' extend to 19" widescreen @ 1440x900

Option Explicit
Dim WshShell, Dummy, Splash
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Call DoIt
WScript.Quit

Sub DoIt
wshshell.Run("%systemroot%\system32\control.exe desk.cpl,@0,3")
WScript.Sleep 1000
WshShell.SendKeys "2"
WScript.Sleep 10
'alt-e to uncheck extend desktop
WshShell.SendKeys "%E"
WScript.Sleep 500
'alt-e to apply changes
WshShell.SendKeys "%A"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500
wshshell.Run("%systemroot%\system32\control.exe desk.cpl,@0,3")
WScript.Sleep 1000
WshShell.SendKeys "2"
WScript.Sleep 10
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
'jumps to highest resolution my monitor/video card supports
WshShell.SendKeys "{END}"
WshShell.SendKeys "{ENTER}"
End Sub



2. collapse.vbs

' collapse to laptop only

Option Explicit
Dim WshShell, Dummy, Splash
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Call DoIt
WScript.Quit

Sub DoIt
wshshell.Run("%systemroot%\system32\control.exe desk.cpl,@0,3")
WScript.Sleep 1000
WshShell.SendKeys "2"
WScript.Sleep 10
'alt-e to uncheck 'extend'
WshShell.SendKeys "%E"
WScript.Sleep 500
WshShell.SendKeys "%A"
WshShell.SendKeys "{ENTER}"
End Sub



I ran systeminfo in case someone doesn't know where I'm coming from.
Host Name:                 ICARUS
OS Name:                   Microsoft Windows XP Professional
OS Version:                5.1.2600 Service Pack 2 Build 2600
System type:               X86-based PC
dannyp's avatar
16 years ago
link
dannyp
dʎuuɐp
I have a folder in My Documents called toolbars where my toolbar shortcut icons reside. I dropped a new scripts folder in with the two scripts I made above. I changed the icon to a monitor and two monitors with triangle hazard exclamation signs. Here's where they are located:


%SystemRoot%\system32\xpsp2res.dll
ozntz's avatar
16 years ago
link
ozntz
toooooooooooooooooooooooooooooooooo
Nice I have looked for the same thing and failed to come up with a good solution but this looks like it will work. Thanks for posting that
asemisldkfj's avatar
16 years ago
link
asemisldkfj
the law is no protection
pretty cool!
dannyp's avatar
16 years ago
link
dannyp
dʎuuɐp
just make sure you don't try multitasking when it's executing, the sendkeys get kinda screwy if you do.