Sign in to follow this  
Followers 0
AlienStar

why not in all windows versions ??!!!

12 posts in this topic

#1 ·  Posted (edited)

hello everybody

why can't some scripts run in some windows versions ??

I have this script to change desktop resolution

#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 by AlienStar

Share this post


Link to post
Share on other sites



maybe they run 64bit OS? Or adminrights missing?

Share this post


Link to post
Share on other sites

I'm sure all windows' I test in ... 32 bit

but how can I know about adminrights missing ??

Share this post


Link to post
Share on other sites

IsAdmin()


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 junk

its something else

maybe parameters such as $DM_PELSWIDTH = 0x00080000 are not same for everyone ?

Edited by Gettingsmarter

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 junk

its something else

maybe parameters such as $DM_PELSWIDTH = 0x00080000 are not same for everyone ?

guys please ... I wanna a solution ...

Edited by AlienStar

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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>&nbsp;" & $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>&nbsp;" & $objItem.Caption & "</td></tr>" & @CRLF
        $Output &= "<tr><td>Description</td><td>&nbsp;" & $objItem.Description & "</td></tr>" & @CRLF
        $Output &= "<tr><td>HorizontalResolution</td><td>&nbsp;" & $objItem.HorizontalResolution & "</td></tr>" & @CRLF
        $Output &= "<tr><td>MaxRefreshRate</td><td>&nbsp;" & $objItem.MaxRefreshRate & "</td></tr>" & @CRLF
        $Output &= "<tr><td>MinRefreshRate</td><td>&nbsp;" & $objItem.MinRefreshRate & "</td></tr>" & @CRLF
        $Output &= "<tr><td>NumberOfColors</td><td>&nbsp;" & $objItem.NumberOfColors & "</td></tr>" & @CRLF
        $Output &= "<tr><td>RefreshRate</td><td>&nbsp;" & $objItem.RefreshRate & "</td></tr>" & @CRLF
        $Output &= "<tr><td>ScanMode</td><td>&nbsp;" & $objItem.ScanMode & "</td></tr>" & @CRLF
        $Output &= "<tr><td>SettingID</td><td>&nbsp;" & $objItem.SettingID & "</td></tr>" & @CRLF
        $Output &= "<tr><td>VerticalResolution</td><td>&nbsp;" & $objItem.VerticalResolution & "</td></tr>" & @CRLF
        $Output &= "<tr><td>--------------------</td><td>&nbsp;--------------------</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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Was waiting for chicken to cook, so I combined them for you:

#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 by danwilli
1 person likes this

Share this post


Link to post
Share on other sites

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.

danwilli you're right

you got tired with me ... thanks so much for help ...

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0