mbailey Posted December 16, 2005 Share Posted December 16, 2005 Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' File: wxp_screenResolution.vbs '' Created: Wed 12/14/2005 17:43:28.75 '' Author: mikeb '' '' Modification history: '' Date Author Desc '' ---- ------ ---- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Const C_s_WINDOWTITLE = "Display Properties" Const C_s_WINDOWTITLE_MONITOR_SETTINGS = "Monitor Settings" Const C_s_TAB_CONTROL = "12320" Const C_s_CTRL_SHIFT_TAB = "+^{TAB}" Const C_s_SLIDER_CONTROL = "1808" Const C_n_MAX_RESOLUTION_ATTEMPTS = 32 Const C_s_RESOLUTION_STATIC_TEXT = "1814" Const C_s_1024x768 = "1024 by 768 pixels" Const C_s_ID_OK = "1" Const C_s_ID_CANCEL = "2" Const C_s_ID_YES_MONITOR_SETTINGS = "6" Const C_n_POST_OK_DELAY_IN_MILLISECONDS = 2000 Call WScript.Quit( Main() ) Function Main() Dim oShell Dim oAutoIt Dim sResolution Dim nAttempt Set oShell = WScript.CreateObject("WScript.Shell") Set oAutoIt = WScript.CreateObject("AutoItX3.Control") sResolution = "" nAttempt = 0 '' Assuming failure; Later sets return value '' to 0 if the desired resolution is found Main = 1 Call WScript.Echo("Running desktop control panel") Call oShell.Run("control.exe desktop", 1, FALSE) Call WScript.Echo("Waiting for " & C_s_WINDOWTITLE & " dialog") Call oAutoIt.WinWaitActive(C_s_WINDOWTITLE, "") Call WScript.Echo("Sending CTR+SHIFT+TAB to Tab control") Call oAutoIt.ControlSend(C_s_WINDOWTITLE, "", C_s_TAB_CONTROL, C_s_CTRL_SHIFT_TAB, 0) Call WScript.Echo("Sending <END> to Slider control") Call oAutoIt.ControlSend(C_s_WINDOWTITLE, "", C_s_SLIDER_CONTROL, "{END}", 0) Call WScript.Echo("Looping through resolutions") For nAttempt = 0 To C_n_MAX_RESOLUTION_ATTEMPTS sResolution = oAutoIt.ControlGetText(C_s_WINDOWTITLE, "", C_s_RESOLUTION_STATIC_TEXT) Call WScript.Echo("Found " & sResolution) If sResolution <> C_s_1024x768 Then Call WScript.Echo("Moving Slider control to the left one notch") Call oAutoIt.ControlSend(C_s_WINDOWTITLE, "", C_s_SLIDER_CONTROL, "{LEFT}", 0) Else '' Main=0 Indicates that the desired resolution was found Main = 0 Call WScript.Echo("Clicking OK") Call oAutoIt.ControlClick(C_s_WINDOWTITLE, "", C_s_ID_OK) Call WScript.Sleep(C_n_POST_OK_DELAY_IN_MILLISECONDS) If oAutoIt.WinExists(C_s_WINDOWTITLE_MONITOR_SETTINGS,"") Then Call WScript.Echo("Clicking Yes") Call oAutoIt.ControlClick(C_s_WINDOWTITLE_MONITOR_SETTINGS, "", C_s_ID_YES_MONITOR_SETTINGS) End If Exit For End If Next If Not Main = 0 Then Call WScript.Echo("Failed to find " & C_s_RESOLUTION_STATIC_TEXT & ", clicking Cancel") Call oAutoIt.ControlClick(C_s_WINDOWTITLE, "", C_s_ID_CANCEL) End If Call WScript.Echo("Waiting for " & C_s_WINDOWTITLE & " dialog to close") Call oAutoIt.WinWaitClose(C_s_WINDOWTITLE, "") '' Get out of here Call WScript.Echo("Done.") Set oAutoIt = Nothing Set oShell = Nothing End Function Link to comment Share on other sites More sharing options...
poisonkiller Posted December 16, 2005 Share Posted December 16, 2005 This is Autoit forum, not VBS i think... Or you want that someone transport your code to Autoit code? Link to comment Share on other sites More sharing options...
Valuater Posted December 16, 2005 Share Posted December 16, 2005 this can get you started here Local $RUNDLL32 = @SystemDir & "\rundll32.exe" Run($RUNDLL32 & " shell32.dll,Control_RunDLL desk.cpl") WinWait("Display Properties") Send("^+{TAB}") 8) Link to comment Share on other sites More sharing options...
Gigglestick Posted December 16, 2005 Share Posted December 16, 2005 (edited) This is Autoit forum, not VBS i think... Or you want that someone transport your code to Autoit code?Note the line: Set oAutoIt = WScript.CreateObject("AutoItX3.Control") It is VBScript using the AutoITX.dll. I don't know why someone would script this in VBS instead of AutoIt, but it is essentially an AutoIt script... just an odd, roundabout way of doing it. Edited December 16, 2005 by c0deWorm My UDFs: ExitCodes Link to comment Share on other sites More sharing options...
Gigglestick Posted December 16, 2005 Share Posted December 16, 2005 @mbailey Why do you keep making your scripts in VBScript using the AutoItX control? Why not just code in AutoIt? What exactly are you gaining, or think you're gaining, by doing it this way? What I mean is that AutoIt is at least as easy to learn as VBScript, so if you have a grasp on VBScript (which it appears you do) then you should have no trouble at all learning AutoIt. Please don't read this as an attack. I'm just curious. My UDFs: ExitCodes Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now