When I use VBS in a HTML file, I can get the screen width and height with
width=screen.width
and
height=screen.height

I would like to get the width and height in a stand alone .vbs script so that I
can place display objects where I want them in relation to the screen size. Can
anybody help?
--
Crash

Re: Getting screen parameters in a script by Al

Al
Sun Jan 22 13:54:58 CST 2006


""Crash" Dummy" <dvader@deathstar.mil> wrote in message
news:O$L0703HGHA.1728@TK2MSFTNGP09.phx.gbl...
> When I use VBS in a HTML file, I can get the screen width and height with
> width=screen.width
> and
> height=screen.height
>
> I would like to get the width and height in a stand alone .vbs script so
> that I
> can place display objects where I want them in relation to the screen
> size. Can
> anybody help?

One way would be to create an IE instance and extract the screen.width and
screen.height properties as you have done above. Try this:


with WScript.createobject("internetexplorer.application")
.navigate "about:blank"
sw = .document.parentwindow.screen.width
sh = .document.parentwindow.screen.height
.quit
End With

WScript.Echo "screen resolution is " & sw & " by " & sh

/Al



Re: Getting screen parameters in a script by \

\
Sun Jan 22 13:03:13 CST 2006

> One way would be to create an IE instance and extract the screen.width and
> screen.height properties as you have done above. Try this:

Thanks. I thought of that. I was hoping for something a little cleaner and more
direct.
--
Crash



Re: Getting screen parameters in a script by Alexander

Alexander
Mon Jan 23 01:54:26 CST 2006

"Crash" Dummy schrieb:
>> One way would be to create an IE instance and extract the screen.width and
>> screen.height properties as you have done above. Try this:
>
> Thanks. I thought of that. I was hoping for something a little cleaner and more
> direct.

If you have VB or VB-5-CCE you only need to put

GetSystemMetrics(SM_CXSCREEN) ' 1st monitors screen width in pixels
GetSystemMetrics(SM_CYSCREEN) ' 1st monitors screen height in pixels

into a ActiveX-wrapper for getting screen-resolution (and may other
system-coord-settings)

Best regards,
Alex

Re: Getting screen parameters in a script by jefrie

jefrie
Mon Jan 23 04:32:05 CST 2006

In a standalone vb script you might use WMI

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT Caption, PelsHeight,
PelsWidth FROM Win32_DisplayConfiguration")
For Each objItem in colItems
Wscript.Echo "Caption -- " & objItem.Caption
Wscript.Echo "PelsHeight -- " & objItem.PelsHeight
Wscript.Echo "PelsWidth -- " & objItem.PelsWidth
Next

You get the actual configuration for each adapter. Maybe you can work with
this.
Regards
Jens Frieben

--
Jens Frieben (Germany)


"Alexander Mueller" wrote:

> "Crash" Dummy schrieb:
> >> One way would be to create an IE instance and extract the screen.width and
> >> screen.height properties as you have done above. Try this:
> >
> > Thanks. I thought of that. I was hoping for something a little cleaner and more
> > direct.
>
> If you have VB or VB-5-CCE you only need to put
>
> GetSystemMetrics(SM_CXSCREEN) ' 1st monitors screen width in pixels
> GetSystemMetrics(SM_CYSCREEN) ' 1st monitors screen height in pixels
>
> into a ActiveX-wrapper for getting screen-resolution (and may other
> system-coord-settings)
>
> Best regards,
> Alex
>

Re: Getting screen parameters in a script by y

y
Mon Jan 23 04:47:43 CST 2006

"Crash" Dummy" <dvader@deathstar.mil> wrote in message
news:%23Z%23u$Z4HGHA.2668@tk2msftngp13.phx.gbl...
>> One way would be to create an IE instance and extract the screen.width
>> and
>> screen.height properties as you have done above. Try this:
>
> Thanks. I thought of that. I was hoping for something a little cleaner and
> more
> direct.

You can also get width and height like this.
(I don't know this is clean or direct (^^) )

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


Re: Getting screen parameters in a script by \

\
Mon Jan 23 07:54:02 CST 2006

Thanks to all. It doesn't look like there is a "simple, direct" way to get
screen parameters. I'll save these methods in my "snippets" file and use
whichever is appropriate for a particular script.
--
Crash



Re: Getting screen parameters in a script by \

\
Mon Jan 23 08:17:22 CST 2006

> You can also get width and height like this.
> (I don't know this is clean or direct (^^) )

It's the cleanest yet. :-)
--
Crash



Re: Getting screen parameters in a script by \

\
Mon Jan 23 08:33:42 CST 2006

Where did you get this?

Set HTM = CreateObject("htmlfile")

I searched my script references for "htmlfile" and came up empty.
--
Crash



Re: Getting screen parameters in a script by y

y
Mon Jan 23 08:58:06 CST 2006

""Crash" Dummy" <dvader@deathstar.mil> wrote in message
news:O5OmDoCIGHA.3460@TK2MSFTNGP12.phx.gbl...
> Where did you get this?
>
> Set HTM = CreateObject("htmlfile")
>
Some time ago I find someone use this in News Group.
If you search google with Createobject("htmlfile"),
you may find some sample.

http://groups.google.com/groups?as_q=Createobject%28%22htmlfile%22%29&num=10&scoring=r&hl=en&as_epq=&as_oq=&as_eq=&as_ugroup=&as_usubject=&as_uauthors=&lr=&as_drrb=q&as_qdr=&as_mind=1&as_minm=1&as_miny=1981&as_maxd=23&as_maxm=1&as_maxy=2006&safe=off

Y Sakuda from JPN



Re: Getting screen parameters in a script by \

\
Mon Jan 23 09:14:01 CST 2006

> Some time ago I find someone use this in News Group.
> If you search google with Createobject("htmlfile"),
> you may find some sample.

Thanks. I did a Google search, but I was hoping for something more solid, like a
MS reference. I also hear about VB features for the first time in these groups,
and I like to follow up with primary source documentation.
--
Crash



Re: Getting screen parameters in a script by y

y
Mon Jan 23 09:24:51 CST 2006

""Crash" Dummy" <dvader@deathstar.mil> wrote in message
news:OAfOl%23CIGHA.1676@TK2MSFTNGP09.phx.gbl...
>> Some time ago I find someone use this in News Group.
>> If you search google with Createobject("htmlfile"),
>> you may find some sample.
>
> Thanks. I did a Google search, but I was hoping for something more solid,
> like a
> MS reference.
Sorry. Unfortunately I could'nt find official document.
Y Sakuda from JPN




Re: Getting screen parameters in a script by Alexander

Alexander
Mon Jan 23 09:38:38 CST 2006

"Crash" Dummy schrieb:
>> Some time ago I find someone use this in News Group.
>> If you search google with Createobject("htmlfile"),
>> you may find some sample.
>
> Thanks. I did a Google search, but I was hoping for something more solid, like a
> MS reference. I also hear about VB features for the first time in these groups,
> and I like to follow up with primary source documentation.

"htmfile" is the ProgID for the document-object-model for HTML
(the so-called DOM). A very detailed reference to this huge interface
is the MSDN-web-workshop:

http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

The screen- and window-object's references are to be found here
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_screen.asp?frame=true
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_window.asp?frame=true


Mfg,
Alex

Re: Getting screen parameters in a script by \

\
Mon Jan 23 09:54:52 CST 2006

> "htmfile" is the ProgID for the document-object-model for HTML
> (the so-called DOM). A very detailed reference to this huge interface
> is the MSDN-web-workshop:

Thank you. That's what I was looking for. So much stuff! So little time...
--
Crash



Re: Getting screen parameters in a script by Al

Al
Mon Jan 23 20:03:43 CST 2006


""Crash" Dummy" <dvader@deathstar.mil> wrote in message
news:%23Z%23u$Z4HGHA.2668@tk2msftngp13.phx.gbl...
>> One way would be to create an IE instance and extract the screen.width
>> and
>> screen.height properties as you have done above. Try this:
>
> Thanks. I thought of that. I was hoping for something a little cleaner and
> more
> direct.

You're welcome.

More direct? Since VBScript has no such native capability, it can only get
it from some other provider. Someone posted a WMI solution that I would
assume to be as good as the one I came up with, and their could be others.
How would you relate these in terms of "directness"?

Cleaner? What does that mean if it means something other than more direct?

/Al



Re: Getting screen parameters in a script by Al

Al
Mon Jan 23 20:04:40 CST 2006


"Alexander Mueller" <millerax@hotmail.com> wrote in message
news:43d48bb3$0$21021$9b4e6d93@newsread2.arcor-online.net...
> "Crash" Dummy schrieb:
>>> One way would be to create an IE instance and extract the screen.width
>>> and
>>> screen.height properties as you have done above. Try this:
>>
>> Thanks. I thought of that. I was hoping for something a little cleaner
>> and more
>> direct.
>
> If you have VB or VB-5-CCE you only need to put
>
> GetSystemMetrics(SM_CXSCREEN) ' 1st monitors screen width in pixels
> GetSystemMetrics(SM_CYSCREEN) ' 1st monitors screen height in pixels
>
> into a ActiveX-wrapper for getting screen-resolution (and may other
> system-coord-settings)

How would you rate that solution on the "more direct" scale, "Crash"?

/Al



Re: Getting screen parameters in a script by \

\
Tue Jan 24 07:44:14 CST 2006

> How would you rate that solution on the "more direct" scale, "Crash"?

I'd have to understand it, first. :-)

I'm fine up until

> into a ActiveX-wrapper for getting screen-resolution (and may other
> system-coord-settings)

I haven't a clue what that means.
--
Crash



Re: Getting screen parameters in a script by \

\
Tue Jan 24 07:50:46 CST 2006

> More direct? Since VBScript has no such native capability, it can only get
> it from some other provider. Someone posted a WMI solution that I would
> assume to be as good as the one I came up with, and their could be others.
> How would you relate these in terms of "directness"?

As you say, VBS has no such native capability, so I have stashed the other
offers for later use, depending on the context. If I am using IE for display, as
I often do, then that will be the most direct and cleanest method. If I am using
some other relocatable device, like an Input Box, y yakuda's suggestion is the
most appealing.
--
Crash



Re: Getting screen parameters in a script by Alexander

Alexander
Tue Jan 24 07:57:50 CST 2006

Al Dunbar schrieb:
> "Alexander Mueller" <millerax@hotmail.com> wrote in message
> news:43d48bb3$0$21021$9b4e6d93@newsread2.arcor-online.net...
>> "Crash" Dummy schrieb:
>>>> One way would be to create an IE instance and extract the screen.width
>>>> and
>>>> screen.height properties as you have done above. Try this:
>>> Thanks. I thought of that. I was hoping for something a little cleaner
>>> and more
>>> direct.
>> If you have VB or VB-5-CCE you only need to put
>>
>> GetSystemMetrics(SM_CXSCREEN) ' 1st monitors screen width in pixels
>> GetSystemMetrics(SM_CYSCREEN) ' 1st monitors screen height in pixels
>>
>> into a ActiveX-wrapper for getting screen-resolution (and may other
>> system-coord-settings)
>
> How would you rate that solution on the "more direct" scale, "Crash"?
>
> /Al
>
>

Although i am not "Crash" it, only takes 5 min to put these lines into a
vb-class 'ScreenRes'

Public Property Get ScreenWidth () As Long
ScreenWidth = GetSystemMetrics(SM_CXSCREEN)
End Property
Public Property Get ScreenHeight () As Long
ScreenHeight = GetSystemMetrics(SM_CYSCREEN)
End Property

compile it and call it by vbscript

set sysMetrics = CreateObject("myLib.ScreenRes")
WSH.Echo sysMetrics.ScreenWidth , sysMetrics.ScreenHeight



Mfg
Alex

Re: Getting screen parameters in a script by \

\
Tue Jan 24 08:32:57 CST 2006

> compile it and call it by vbscript

Unfortunately, I don't have (or want) a compiler. I have the VB engine to run VB
executables, but no compiler.
--
Crash



Re: Getting screen parameters in a script by Fosco

Fosco
Tue Jan 24 20:26:53 CST 2006

""Crash" Dummy"
>I did a Google search, but I was hoping for something more solid

In my win98se :

'HKEY_LOCAL_MACHINE\Config\0001\Display\Settings


set oShell = CreateObject("WScript.Shell")
' 001 e variabile dal sistema e vari profili installati
' Profile refers to hardware profiles, not user profiles.
bKey = oShell.RegRead("HKLM\Config\0001\Display\Settings\Resolution")
b2Key = oShell.RegRead("HKLM\Config\0001\Display\Settings\BitsPerPixel")
Wscript.Echo bKey
Wscript.Echo b2Key &" bit"


--
Fosco




Re: Getting screen parameters in a script by Michael

Michael
Tue Jan 24 21:10:55 CST 2006

"Crash" Dummy wrote:
> Thanks to all. It doesn't look like there is a "simple, direct" way
> to get screen parameters. I'll save these methods in my "snippets"
> file and use whichever is appropriate for a particular script.


On NT4 with WMI installed or any more recent OS version that comes natively
with WMI (even handles the multi-monitor case - that excludes me ;-).

set monitors = GetObject("winmgmts:").instancesOf("Win32_DesktopMonitor")
for each monitor in monitors
with monitor
res = .ScreenWidth & "x" & .ScreenHeight
wscript.echo res
end with
next



--
Michael Harris
Microsoft MVP Scripting





Re: Getting screen parameters in a script by \

\
Wed Jan 25 07:46:07 CST 2006

> On NT4 with WMI installed or any more recent OS version that comes natively
> with WMI (even handles the multi-monitor case - that excludes me ;-).

> set monitors = GetObject("winmgmts:").instancesOf("Win32_DesktopMonitor")
> for each monitor in monitors
> with monitor
> res = .ScreenWidth & "x" & .ScreenHeight
> wscript.echo res
> end with
> next

Another one for my collection!

I have another, more general, question. Is there any way to extract items in a
collection like this without the for-next loop? For example, something like
monitors(0)? (I know that doesn't work.)
--
Crash



Re: Getting screen parameters in a script by Michael

Michael
Wed Jan 25 19:17:58 CST 2006

> I have another, more general, question. Is there any way to extract
> items in a collection like this without the for-next loop? For
> example, something like monitors(0)? (I know that doesn't work.)

Technically, yes, but practically, no (especially with your direct and
straightforward code objective ;-)...

SWbemObjectSet.Item(String,Object) method [WMI]
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/swbemobjectset_item.asp?frame=true

And no, I don't of any useful pratical examples of calling the Item method.

--
Michael Harris
Microsoft MVP Scripting





Re: Getting screen parameters in a script by \

\
Wed Jan 25 19:45:47 CST 2006

> Technically, yes, but practically, no (especially with your direct and
> straightforward code objective ;-)...

Just thought I'd ask... :-)
--
Crash