AlienStar Posted September 14, 2009 Share Posted September 14, 2009 (edited) hello everybody why can't some scripts run in some windows versions ?? I have this script to change desktop resolution expandcollapse popup#RequireAdmin DisplayChangeRes(1024, 768, 32, 85) Func DisplayChangeRes($WIDTH, $HEIGHT, $BPP, $FREQ) $DM_PELSWIDTH = 0x00080000 $DM_PELSHEIGHT = 0x00100000 $DM_BITSPERPEL = 0x00040000 $DM_DISPLAYFREQUENCY = 0x00400000 $CDS_TEST = 0x00000002 $CDS_UPDATEREGISTRY = 0x00000001 $DISP_CHANGE_RESTART = 1 $DISP_CHANGE_SUCCESSFUL = 0 $HWND_BROADCAST = 0xffff $WM_DISPLAYCHANGE = 0x007E $DEVMODE = DLLStructCreate ("byte[32];int[10];byte[32];int[6]") $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DLLStructGetPtr ($DEVMODE)) If @error Then $B = 0 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, $WIDTH, 2) DllStructSetData ($DEVMODE, 4, $HEIGHT, 3) DllStructSetData ($DEVMODE, 4, $BPP, 1) DllStructSetData ($DEVMODE, 4, $FREQ, 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", $BPP, "int", $HEIGHT * 2 ^ 16 + $WIDTH) $DEVMODE = "" Return 1 Case Else $DEVMODE = "" Return $B EndSelect EndIf EndFunc ;==>DisplayChangeRes it works in my windows vista but I used it in some of my friend's windows' (vista/xp) but It didn't work please tell me why this .... thanks Edited September 14, 2009 by AlienStar Link to comment Share on other sites More sharing options...
andygo Posted September 14, 2009 Share Posted September 14, 2009 maybe they run 64bit OS? Or adminrights missing? Link to comment Share on other sites More sharing options...
AlienStar Posted September 14, 2009 Author Share Posted September 14, 2009 I'm sure all windows' I test in ... 32 bit but how can I know about adminrights missing ?? Link to comment Share on other sites More sharing options...
dantay9 Posted September 14, 2009 Share Posted September 14, 2009 IsAdmin() Link to comment Share on other sites More sharing options...
AlienStar Posted September 14, 2009 Author Share Posted September 14, 2009 I put #RequireAdmin IsAdmin() would you explain more ??? Link to comment Share on other sites More sharing options...
microbious Posted September 14, 2009 Share Posted September 14, 2009 (edited) I put #RequireAdmin I dont think admin is the problem here, i ran your script and nothing happened and i only have one account on my computer that is ADMINISTRATOR. BUT i run windows 7 and am pretty sure its same junk its something else maybe parameters such as $DM_PELSWIDTH = 0x00080000 are not same for everyone ? Edited September 14, 2009 by Gettingsmarter Link to comment Share on other sites More sharing options...
AlienStar Posted September 14, 2009 Author Share Posted September 14, 2009 (edited) I dont think admin is the problem here, i ran your script and nothing happened and i only have one account on my computer that is ADMINISTRATOR.BUT i run windows 7 and am pretty sure its same junkits something elsemaybe parameters such as $DM_PELSWIDTH = 0x00080000 are not same for everyone ?guys please ... I wanna a solution ... Edited September 15, 2009 by AlienStar Link to comment Share on other sites More sharing options...
DW1 Posted September 15, 2009 Share Posted September 15, 2009 Hi AlienStar The reason is because you have entered in a resolution or frequency (most likely the 85 on freq) that the users hardware does not support. If this is the exact script and settings you are running, you will find that most people's monitors will only support a frequency of 60. Getting smarter, I bet if you change: DisplayChangeRes(1024, 768, 32, 85) to DisplayChangeRes(1024, 768, 32, 60) it would work for you. AutoIt3 Online Help Link to comment Share on other sites More sharing options...
DW1 Posted September 15, 2009 Share Posted September 15, 2009 You could add some logic to check a list of available resolution/frequency/color combos for error checking. Here is a quick way to get all available resolutions sets for a machine using WMI (thanks to AI Scriptomatic) ; Generated by AutoIt Scriptomatic September 14, 2009 $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output = "" $Output = $Output & '<html><head><title>Scriptomatic HTML Output</title></head><body> <style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th>Property</th><th>Value</th></tr>' $Output &= '<tr bgcolor="yellow"><td>' & "Computer</td><td> " & $strComputer & "</td></tr>" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("SELECT * FROM CIM_VideoControllerResolution", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems $Output &= "<tr><td>Caption</td><td> " & $objItem.Caption & "</td></tr>" & @CRLF $Output &= "<tr><td>Description</td><td> " & $objItem.Description & "</td></tr>" & @CRLF $Output &= "<tr><td>HorizontalResolution</td><td> " & $objItem.HorizontalResolution & "</td></tr>" & @CRLF $Output &= "<tr><td>MaxRefreshRate</td><td> " & $objItem.MaxRefreshRate & "</td></tr>" & @CRLF $Output &= "<tr><td>MinRefreshRate</td><td> " & $objItem.MinRefreshRate & "</td></tr>" & @CRLF $Output &= "<tr><td>NumberOfColors</td><td> " & $objItem.NumberOfColors & "</td></tr>" & @CRLF $Output &= "<tr><td>RefreshRate</td><td> " & $objItem.RefreshRate & "</td></tr>" & @CRLF $Output &= "<tr><td>ScanMode</td><td> " & $objItem.ScanMode & "</td></tr>" & @CRLF $Output &= "<tr><td>SettingID</td><td> " & $objItem.SettingID & "</td></tr>" & @CRLF $Output &= "<tr><td>VerticalResolution</td><td> " & $objItem.VerticalResolution & "</td></tr>" & @CRLF $Output &= "<tr><td>--------------------</td><td> --------------------</td></tr>" & @CRLF Next If FileExists( @TempDir & "\CIM_VideoControllerResolution.HTML" ) Then FileDelete( @TempDir & "\CIM_VideoControllerResolution.HTML" ) FileWrite(@TempDir & "\CIM_VideoControllerResolution.HTML", $Output) Run(@ComSpec & " /c start " & @TempDir & "\CIM_VideoControllerResolution.HTML") Else MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "CIM_VideoControllerResolution") EndIf AutoIt3 Online Help Link to comment Share on other sites More sharing options...
DW1 Posted September 15, 2009 Share Posted September 15, 2009 (edited) Was waiting for chicken to cook, so I combined them for you: expandcollapse popup#RequireAdmin If DisplayChangeRes(1920, 1080, 32, 60) = 0 Then MsgBox(0, "Error", "Invalid resolution selected") Func DisplayChangeRes($WIDTH, $HEIGHT, $BPP, $FREQ) If CheckDisplay($WIDTH, $HEIGHT, $BPP, $FREQ) = 0 Then Return 0 EndIf $DM_PELSWIDTH = 0x00080000 $DM_PELSHEIGHT = 0x00100000 $DM_BITSPERPEL = 0x00040000 $DM_DISPLAYFREQUENCY = 0x00400000 $CDS_TEST = 0x00000002 $CDS_UPDATEREGISTRY = 0x00000001 $DISP_CHANGE_RESTART = 1 $DISP_CHANGE_SUCCESSFUL = 0 $HWND_BROADCAST = 0xffff $WM_DISPLAYCHANGE = 0x007E $DEVMODE = DllStructCreate("byte[32];int[10];byte[32];int[6]") $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DllStructGetPtr($DEVMODE)) If @error Then $B = 0 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, $WIDTH, 2) DllStructSetData($DEVMODE, 4, $HEIGHT, 3) DllStructSetData($DEVMODE, 4, $BPP, 1) DllStructSetData($DEVMODE, 4, $FREQ, 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", $BPP, "int", $HEIGHT * 2 ^ 16 + $WIDTH) $DEVMODE = "" Return 1 Case Else $DEVMODE = "" Return $B EndSelect EndIf Return 1 EndFunc ;==>DisplayChangeRes Func CheckDisplay($w, $h, $bit, $f) $flag = 0 $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("SELECT * FROM CIM_VideoControllerResolution", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems If $w = $objItem.HorizontalResolution And $h = $objItem.VerticalResolution And 2^$bit = $objItem.NumberOfColors And $f = $objItem.RefreshRate Then $flag = 1 Next EndIf Return $flag EndFunc ;==>CheckDisplay Edited September 15, 2009 by danwilli aa2zz6, mLipok and sylremo 3 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
AlienStar Posted September 15, 2009 Author Share Posted September 15, 2009 Hi AlienStarThe reason is because you have entered in a resolution or frequency (most likely the 85 on freq) that the users hardware does not support. If this is the exact script and settings you are running, you will find that most people's monitors will only support a frequency of 60.Getting smarter, I bet if you change:DisplayChangeRes(1024, 768, 32, 85)toDisplayChangeRes(1024, 768, 32, 60)it would work for you.danwilli you're rightyou got tired with me ... thanks so much for help ... Link to comment Share on other sites More sharing options...
jgustavo Posted August 17, 2013 Share Posted August 17, 2013 sorry for revive the thread. I'm using the function _ChangeScreenRes and it works on almost all computers, xp, vista, 7, 32 and 64bit. but in some not work. may be the fault of drivers, antivirus, anything else? I can not find the cause. 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