[VBS] screen size

Hello everyone!
I am looking for a way to know the screen size in VBS. Here is the beginning of my script:

Dim x, y
x = Screen.Width
y = Screen.Height

msgbox "Screen size: " & x & "x" & y, vbSystemModal, "Size"

x = 0
y = 0


Unfortunately, when opening the file, there is an error stating that "Screen" is undefined.
Could someone help me?
Thanks in advance.
Configuration: Windows XP Media Center Edition 2005 Firefox 2.0.0.11

8 answers

  1. It takes 3 minutes on Google :

    Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean

    Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long
    Private Const CCDEVICENAME = 32
    Private Const CCFORMNAME = 32
    Private Const DM_BITSPERPEL = &H60000
    Private Const DM_PELSWIDTH = &H80000
    Private Const DM_PELSHEIGHT = &H100000

    Private Type DEVMODE
    dmDeviceName As String * CCDEVICENAME
    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmYResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * CCFORMNAME
    dmUnusedPadding As Integer
    dmBitsPerPel As Integer
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
    End Type

    ' Inputsim RetValue As Integer
    RetValue = ChangeRes(800, 600, 32)
    '
    ' Returns:1 = Resolution Successfully Ch
    ' anged
    0 = Resolution Was Not Changed

    Function ChangeRes(Width As Single, Height As Single, BPP As Integer) As Integer
    On Error GoTo ERROR_HANDLER
    Dim DevM As DEVMODE, I As Integer, ReturnVal As Boolean, _
    RetValue, OldWidth As Single, OldHeight As Single, _
    OldBPP As Integer
    Call EnumDisplaySettings(0&, -1, DevM)
    OldWidth = DevM.dmPelsWidth
    OldHeight = DevM.dmPelsHeight
    OldBPP = DevM.dmBitsPerPel
    I = 0

    Do
    ReturnVal = EnumDisplaySettings(0&, I, DevM)
    I = I + 1
    Loop Until (ReturnVal = False)
    DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
    DevM.dmPelsWidth = Width
    DevM.dmPelsHeight = Height
    DevM.dmBitsPerPel = BPP
    Call ChangeDisplaySettings(DevM, 1)
    RetValue = MsgBox("Do You Wish To Keep Your Screen Resolution To " & Width & "x" & Height & " - " & BPP & " BPP?", vbQuestion + vbOKCancel, "Change Resolution Confirm:")

    If RetValue = vbCancel Then
    DevM.dmPelsWidth = OldWidth
    DevM.dmPelsHeight = OldHeight
    DevM.dmBitsPerPel = OldBPP
    Call ChangeDisplaySettings(DevM, 1)
    MsgBox "Old Resolution(" & OldWidth & " x " & OldHeight & ", " & OldBPP & " Bit) Successfully Restored!", vbInformation + vbOKOnly, "Resolution Confirm:"
    ChangeRes = 0
    Else
    ChangeRes = 1
    End If
    Exit Function
    ERROR_HANDLER:
    ChangeRes = 0
    End Function
    1
    1. ```vb
      Private Sub Form_Load()

      Dim X As Long
      Dim Y As Long

      ' Width
      X = (Screen.Width \ Screen.TwipsPerPixelX)
      ' Height
      Y = (Screen.Height \ Screen.TwipsPerPixelY)

      MsgBox "Here is the screen resolution: " & Chr$(13) & Chr$(13) & X & "x" & Y, vbOkOnly + vbInformation, "Resolution"

      End Sub
      ```
      0
      1. Hello again,

        I put the code in my script, but there are errors. I think it's because it's Visual Basic, not Visual Basic SCRIPT (VBS).
        Anyway, thanks anyway.
        0
        1. I did a little research, but I didn't find anything for VBS, but I think this will help

          http://www.google.com/codesearch?hl=en&q=+createobject+screen+vbs+show:kuV_P5dKAzc:trHQnsR6BiU:OEvYCGwzuGo&sa=N&cd=7&ct=rc&cs_p=http://gentoo.osuosl.org/distfiles/awstats-6.5.tar.gz&cs_f=awstats-6.5/wwwroot/js/awstats_misc_tracker.js
          0
          1. ZAKAPUCE I SAID NO VISUAL BASIC!

            uh, hey, tarek_dotzero, I didn't understand what was written on the page!
            It's very complicated!
            0
            1. I agree with what you're saying, but in VBS the forms do not exist. So Form1.Load (for example) means nothing to Wscript.
              I will try to find the solution through the registry.
              0
              1. If you're working on Windows, WMI is there for that...

                Here's a code that can help you ;)

                Dim gfx, colours, horiz, vert strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_DisplayConfiguration") For Each objItem in colItems gfx = "Name: " & objItem.DeviceName colours = "Color depth: " & objItem.BitsPerPel horiz = "Horizontal resolution: " & objItem.PelsWidth vert = "Vertical resolution: " & objItem.PelsHeight Next msgbox gfx & vbcrlf & colours & vbcrlf & horiz & vbcrlf & vert 
                0