Jump to content

why not in all windows versions ??!!!


AlienStar
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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
Link to comment
Share on other sites

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
Link to comment
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 ...

Link to comment
Share on other sites

  • 3 years later...

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...