1

I found the following vbs script to get the screen resolution

but I would like to save the result in a text file please help me

    Dim HTM, wWidth, wHeight
    Set HTM = CreateObject("htmlfile")
    wWidth = HTM.parentWindow.screen.Width
    wHeight = HTM.parentWindow.screen.Height
    wscript.echo wWidth & "X" & wHeight
frankell
  • 588
  • 5
  • 8

1 Answers1

2

To save it to a new text file you may want to use following VBScript for your needs.

Dim HTM, wWidth, wHeight
Set HTM = CreateObject("htmlfile")
wWidth = HTM.parentWindow.screen.Width
wHeight = HTM.parentWindow.screen.Height
wscript.echo wWidth & "X" & wHeight

Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile("D:\file.txt",2,true)
objFileToWrite.WriteLine("--- screen resolution start -------------------------")
objFileToWrite.WriteLine( wWidth & "X" & wHeight)
objFileToWrite.WriteLine("--- screen resolution end   -------------------------")
objFileToWrite.Close
Set objFileToWrite = Nothing

If you want to append text to the end of an existing text file you can easily change the IOMode parameter to 8 e.g.

("D:\file.txt",8,true)

The true parameter makes sure that the file is newly created or must already exist if false.

help-info.de
  • 1,822
  • 5
  • 17
  • 19