Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

AutoIt Script to Change Screen Resolution to 1280 x 1064 but not on Systems with Higher Resolution

Posted on 2011-09-27
11
Medium Priority
?
5,413 Views
Last Modified: 2012-05-12
I have a script that I found online and it works fantastically, but I need it to not change the screen resolution on monitors that have a higher resolution configured because 1280 x 1064 is our new default setting in our enviroment. I know there is a way to do this but I have not used AutoIt in a very very long time and it has really come a long way from what I have seen and I want to know from you gurus out there if you can throw in an if then else statement or something that can tell the script not to run the screen resolution change if any resolution is higher than 1280 x 1064 that would be great. Here is the AutoIt script:
; Define screen resolution
$Width = 1280
$Height = 1024
$BitsPerPixel = 32
$RefreshRate = 60

; Define and set resolution
_ChangeScreenRes(1280,1024,32,60)

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

Open in new window

0
Comment
Question by:the_ratzenator
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
11 Comments
 
LVL 3

Expert Comment

by:RushB
ID: 36713811
It looks like you need to set the Width, Height, Bits in the script.

Look at line 21 - If the width is "1280,1600,1920" Then... and it will leave it alone. Just set the parameters that are ok with you, and it will only change those that are set lower, or higher than what you allow.
0
 

Author Comment

by:the_ratzenator
ID: 36714044
I see that, but isn't there a way to just tell it that anything over 1280 x 1064 exit?
0
 

Author Comment

by:the_ratzenator
ID: 36739731
I've requested that this question be deleted for the following reason:

No one can answer within a timely manner and therefore leads me to seek alternative avenues for my resolution.
0
Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

 
LVL 3

Expert Comment

by:RushB
ID: 36739426
I gave you a timely answer, the reason no one else answered was because it is correct.

Depending upon the version of AutoIt, you might be able to change the following statement:

If $i_Width > "1280" Or $i_Width = -1 Then $i_Width = @DesktopWidth ; default to current setting
If $i_Height > "1064" 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
0
 
LVL 3

Expert Comment

by:RushB
ID: 36739734
I gave you a timely answer, the reason no one else answered was because it is correct.

Depending upon the version of AutoIt, you might be able to change the following statement:

If $i_Width > "1280" Or $i_Width = -1 Then $i_Width = @DesktopWidth ; default to current setting
If $i_Height > "1064" 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
0
 
LVL 11

Expert Comment

by:TheGorby
ID: 36817857
Or even easier, replace lines 7 and 8 with this:
If $Width = @DesktopWidth And $Height = @DesktopHeight And $BitsPerPixel = @DesktopDepth And $RefreshRate = @DesktopRefresh Then
    Exit
Else
    ; Define and set resolution
    _ChangeScreenRes(1280,1024,32,60)
EndIf

Open in new window

0
 
LVL 11

Assisted Solution

by:TheGorby
TheGorby earned 2000 total points
ID: 36896555
Actually now that I look at it, I goofed a bit. It should be this:
If $Width >= @DesktopWidth And $Height >= @DesktopHeight And $BitsPerPixel >= @DesktopDepth And $RefreshRate >= @DesktopRefresh Then  
    Exit  
Else  
    ; Define and set resolution  
    _ChangeScreenRes(1280,1024,32,60)  
EndIf

Open in new window

0
 

Accepted Solution

by:
the_ratzenator earned 0 total points
ID: 36932284
I just used this:

If @DesktopWidth > 1280 Or @DesktopHeight > 1024 Then
 Exit

And it works. I got my answer from a FREE AutoIt forum. Thank you for your responses, I appreciate it.
0
 

Author Comment

by:the_ratzenator
ID: 36932301
Eventhough I did not use your method Gorb, I will give you the points since you were the closest to my resolution.
0
 

Author Closing Comment

by:the_ratzenator
ID: 36954289
I accepted my solution because I researched my issue on an extraneous AutoIt forum and I was provided the code that remedied my problem.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OnPage enhanced its integration with ConnectWise Manage to offer incident responders more control over the ticket and Incident Resolution Lifecycle.
Article by: Shawn
IT teams define success as solving problems quickly. To enable ITSM modernization we have to think of adopting the tools and methods that will enable resolution of ITSM issues more quickly.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question