Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change display sattings automaticly - vbs

3,564 views
Skip to first unread message

Thomas V

unread,
Nov 28, 2006, 3:34:34 AM11/28/06
to
Hi.
When I press CTRL+ALT in vmware and later go back to my VMware
maschine, the resolution is not restored to "full screen" but some
strange resolution. (I have set Fit Visible, Fit Guest...)

I found vbs script to change it automaticly: (it simulates keypress :)
http://justaweebitcloser.com/index.php/site/extended/how_to_change_resolution_in_windows_automatically/

I made some modifications so here it is:
(Mybe you will have to modify sleep times or keypresses :)

'resHigh.vbs - Set screen resolution to 1024x768
'
'Author: Geoffrey Climer
'Version 1.0 - November 1st 2006
'Version 1.1 - 28.11.2006 Thomas V (Check if the resolution is allready
' 1024x768 and opens Display Properties on Settings
page.)
'--------------------------------

toWidth = 1024
toHeight = 768
'--------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" &_
strComputer & "\root\cimv2")
Set colItems=objWMIService.ExecQuery("Select * from
Win32_DisplayConfiguration",,48)

'I have only one display :)
For Each objItem in colItems
DisplayHeight = objItem.PelsHeight
DisplayWidth = objItem.PelsWidth
Next

If (DisplayHeight <> toHeight) Or (DisplayWidth <> toWidth) Then
'Set WshShell Variable and WshNetwork Variable
Set WshShell = WScript.CreateObject("WScript.Shell")

'Run Control Panel to open Display Properties
WshShell.Run("%windir%\system32\control.exe desk.cpl @0,4")

'Set focus on Display Properties window and wait 200 milliseconds
WScript.Sleep 200
WshShell.AppActivate ("Display Properties")
WScript.Sleep 100

'Send keystrokes to move resolution slider all the way to the left
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10

'Send keystrokes to move resolution slider twice to the
right(1024x768)
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10

'Go through the popup dialogues saying "OK" to each
WshShell.SendKeys"{ENTER}"
'WScript.Sleep 10
'WshShell.SendKeys"{ENTER}"
WScript.Sleep 100
WshShell.SendKeys"{TAB}"
WScript.Sleep 10
WshShell.SendKeys"{ENTER}"
End If

'End Script
WScript.Quit


'ResolutionLow.vbs - Set screen resolution back to 800x600
'
'Author: Geoffrey Climer
'Version 1.0 - November 1st 2006
'Version 1.1 - 28.11.2006 Thomas V (Check if the resolution is allready
' 800x600 and opens Display Properties on Settings
page.)
'--------------------------------

toWidth = 800
toHeight = 600
'--------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\"_
& strComputer & "\root\cimv2")
Set colItems=objWMIService.ExecQuery("Select * from
Win32_DisplayConfiguration",,48)

'I have only one display :)
For Each objItem in colItems
DisplayHeight = objItem.PelsHeight
DisplayWidth = objItem.PelsWidth
Next

If (DisplayHeight <> toHeight) Or (DisplayWidth <> toWidth) Then
'Set WshShell Variable and WshNetwork Variable
Set WshShell = WScript.CreateObject("WScript.Shell")

'Run Control Panel to open Display Properties
WshShell.Run("%windir%\system32\control.exe desk.cpl @0,4")

'Set focus on Display Properties window and wait 200 milliseconds
WScript.Sleep 200
WshShell.AppActivate ("Display Properties")
WScript.Sleep 100

'Send keystrokes to change to the settings tab
WshShell.SendKeys"+{TAB}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10

'Send keystrokes to move down to set screen resolution
WshShell.SendKeys"{TAB}"
WScript.Sleep 10

'Send keystrokes to move resolution slider all the way to the left
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10
WshShell.SendKeys"{LEFT}"
WScript.Sleep 10

'Send keystrokes to move resolution slider once to the right (800x600)

'Go through the popup dialogues saying "OK" to each
WshShell.SendKeys"{ENTER}"
WScript.Sleep 10
'WshShell.SendKeys"{ENTER}"
'WScript.Sleep 100
WshShell.SendKeys"{TAB}"
WScript.Sleep 10
WshShell.SendKeys"{ENTER}"
End If

'End Script
WScript.Quit

Best regards,
Thomas.

gcl...@gmail.com

unread,
Nov 28, 2006, 9:19:09 AM11/28/06
to
Thanks for doing this Thomas!

The original script has a few extra lines to check if the username
matches the one you want it to run the script for - in case you do this
in a corporate environment like I do. I didn't want it changing the
resolution for everyone, only for myself.

If you need to, the scripts are available for download at

http://justaweebitcloser.com/files/resHigh.vbs
and
http://justaweebitcloser.com/files/resLow.vbs

with the appropriate changes made. I'm glad someone actually found
this script useful and was able to improve on it!

Geoffrey Climer

Thomas V

unread,
Nov 28, 2006, 12:04:28 PM11/28/06
to
Hi,
Sorry on 800x600 part I forgot to delete:

'Send keystrokes to change to the settings tab
WshShell.SendKeys"+{TAB}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10
WshShell.SendKeys"{RIGHT}"
WScript.Sleep 10
'Send keystrokes to move down to set screen resolution
WshShell.SendKeys"{TAB}"
WScript.Sleep 10


It is not needed anymore, becouse of number 4 at the and:


WshShell.Run("%windir%\system32\control.exe desk.cpl @0,4")

Thomas.


Thomas V je napisal:

Fosco

unread,
Nov 29, 2006, 2:03:43 AM11/29/06
to
"Thomas V"
> I found vbs script [CUT]: (it simulates keypress :)

ahhhrghhh

#include-once
;===============================================================================
;
; Function Name: _ChangeScreenRes()
; Description: Changes the current screen geometry, colour and refresh rate.
; Version: 1.0.0.1
; Parameter(s): $i_Width - Width of the desktop screen in pixels. (horizontal resolution)
; $i_Height - Height of the desktop screen in pixels. (vertical resolution)
; $i_BitsPP - Depth of the desktop screen in bits per pixel.
; $i_RefreshRate - Refresh rate of the desktop screen in hertz.
; Requirement(s): AutoIt Beta > 3.1
; Return Value(s): On Success - Screen is adjusted, @ERROR = 0
; On Failure - sets @ERROR = 1
; Forum(s): http://www.autoitscript.com/forum/index.php?showtopic=20121
; Author(s): Original code - psandu.ro
; Modifications - PartyPooper
;
;===============================================================================
Func _ChangeScreenRes($i_Width = @DesktopWidth, $i_Height = @DesktopHeight, $i_BitsPP = @DesktopDepth, $i_RefreshRate =
@DesktopRefresh)
Local Const $DM_PELSWIDTH = 0x00080000
Local Const $DM_PELSHEIGHT = 0x00100000
Local Const $DM_BITSPERPEL = 0x00040000
Local Const $DM_DISPLAYFREQUENCY = 0x00400000
Local Const $CDS_TEST = 0x00000002
Local Const $CDS_UPDATEREGISTRY = 0x00000001
Local Const $DISP_CHANGE_RESTART = 1
Local Const $DISP_CHANGE_SUCCESSFUL = 0
Local Const $HWND_BROADCAST = 0xffff
Local Const $WM_DISPLAYCHANGE = 0x007E
If $i_Width = "" Or $i_Width = -1 Then $i_Width = @DesktopWidth ; default to current setting
If $i_Height = "" Or $i_Height = -1 Then $i_Height = @DesktopHeight ; default to current setting
If $i_BitsPP = "" Or $i_BitsPP = -1 Then $i_BitsPP = @DesktopDepth ; default to current setting
If $i_RefreshRate = "" Or $i_RefreshRate = -1 Then $i_RefreshRate = @DesktopRefresh ; default to current setting
Local $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]")
Local $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DllStructGetPtr($DEVMODE))
If @error Then
$B = 0
SetError(1)
Return $B
Else
$B = $B[0]
EndIf
If $B <> 0 Then
DllStructSetData($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5)
DllStructSetData($DEVMODE, 4, $i_Width, 2)
DllStructSetData($DEVMODE, 4, $i_Height, 3)
DllStructSetData($DEVMODE, 4, $i_BitsPP, 1)
DllStructSetData($DEVMODE, 4, $i_RefreshRate, 5)
$B = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_TEST)
If @error Then
$B = -1
Else
$B = $B[0]
EndIf
Select
Case $B = $DISP_CHANGE_RESTART
$DEVMODE = ""
Return 2
Case $B = $DISP_CHANGE_SUCCESSFUL
DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DllStructGetPtr($DEVMODE), "int", $CDS_UPDATEREGISTRY)
DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _
"int", $i_BitsPP, "int", $i_Height * 2 ^ 16 + $i_Width)
$DEVMODE = ""
Return 1
Case Else
$DEVMODE = ""
SetError(1)
Return $B
EndSelect
EndIf
EndFunc ;==>_ChangeScreenRes


--
Fosco


gclimer

unread,
Nov 29, 2006, 8:27:21 PM11/29/06
to
Fosco,

That looks like some complicated code.

Thomas, just a note, the changes you made work in Windows XP, but
running the command to open it up to the "Settings" tab doesn't work in
Windows 2000 Pro (at least not on mine), but after some investigation,
I found what would open it correctly:

%windir%\system32\control.exe desk.cpl,,3

Running that works in both XP and 2000, however, you'll need to put
another "Tab" keypress in there before it starts moving the slider
because when opening it with the above command sets the focus on the
color setting.

Fosco

unread,
Nov 30, 2006, 12:26:22 AM11/30/06
to
gclimer:

> Fosco,
> That looks like some complicated code.

http://home.no/aksoftware/products/QRes.zip

http://www.softpedia.com/get/Multimedia/Video/Other-VIDEO-Tools/QRes.shtml

'1 >> 800x600

set oShell = CreateObject("WScript.Shell")
oShell.run"qres.exe /x 800 /y 600"

2 >> 320x240
set oShell = CreateObject("WScript.Shell")
oShell.run"qres.exe /x 320 /y 240"

' ecc
--
Fosco

Fosco

unread,
Nov 30, 2006, 12:27:30 AM11/30/06
to
Fosco:
> http://home.no/aksoftware/products/QRes.zip


Description:

Command line utility to change screen resolution, color depth and
refresh rate...

Command line Examples:

qres.exe /x:640 Changes resolution to 640 x 480.
qres.exe /x 1280 /y 1024 Changes resolution to 1280 x 1024. (If your
graphics card supports it)
qres.exe /c:8 Changes color resolution to 256 colors.
qres.exe /c:16 Changes color resolution to high color (16 bit).
qres.exe /c:24 Changes color resolution to true color (24 bit).**
qres.exe /r:0 Changes the refresh rate to Adapter Default.*
qres.exe /r:-1 Changes the refresh rate to Optimal.*
qres.exe /r:80 Changes the refresh rate to 80 Hz.

* Windows 95/98/Me only.
** On Windows XP you must use 32 bit.

--
Fosco

gclimer

unread,
Nov 30, 2006, 1:14:49 AM11/30/06
to
That looks like a nice utility. If I were able to download software at
work, then that would be an option, but we're limited to what we can do
at work, and a VBScript was the way to go with it.

svendi...@googlemail.com

unread,
Aug 6, 2015, 4:00:53 AM8/6/15
to

>
> If you need to, the scripts are available for download at
>
> http://justaweebitcloser.com/files/resHigh.vbs
> and
> http://justaweebitcloser.com/files/resLow.vbs
>
> with the appropriate changes made. I'm glad someone actually found
> this script useful and was able to improve on it!
>
> Geoffrey Climer

this links dont load.

Evertjan.

unread,
Aug 6, 2015, 4:12:21 AM8/6/15
to
svendi...@googlemail.com wrote on 06 Aug 2015 in
microsoft.public.scripting.vbscript:
Which is to be expected
when you respond to a posting
more than 9 years old,
of 28 Nov 2006 to be exact,
wouldn't you think, Sven?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
0 new messages