Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Center Screen in vbscript

916 views
Skip to first unread message

Derrick Guest

unread,
Nov 3, 2002, 10:19:39 AM11/3/02
to
In VB - no problem..but somehow I'm scratching my head and pulling my hair
out to do this simple 'thing' in vbscript !!

Help much appreciated.

Thanks in advance.

--
Derrick Guest
CompTIA A+ Certified Professional
MCP

Richard T. Edwards

unread,
Nov 3, 2002, 12:22:10 PM11/3/02
to
WMI will get you the size of the current screen settings:

Set Service = GetObject("winmgmts:").execquery("SELECT * FROM
Win32_DesktopMonitor")
For Each Obj In Service
Debug.Print Obj.GetObjectText_
Next

Win32_DesktopMonitor

instance of Win32_DesktopMonitor
{
Availability = 3;
Caption = "ViewSonic 17GS-2";
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_DesktopMonitor";
Description = "ViewSonic 17GS-2";
DeviceID = "DesktopMonitor1";
MonitorManufacturer = "ViewSonic";
MonitorType = "ViewSonic 17GS-2";
Name = "ViewSonic 17GS-2";
PixelsPerXLogicalInch = 96;
PixelsPerYLogicalInch = 96;
PNPDeviceID = "DISPLAY\\VSC394A\\5&32C08D19&1&22446688&01&00";
ScreenHeight = 1024;
ScreenWidth = 1280;
Status = "OK";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "MICROSOF-ANXK7N";
};

You can then respond appropriately.

HTH

"Derrick Guest" <derric...@blueyonder.co.uk> wrote in message
news:uQEU6w0gCHA.3708@tkmsftngp08...

Derrick Guest

unread,
Nov 3, 2002, 12:48:05 PM11/3/02
to
Richard,

Thanks for that - and yes it was a help - though unfortunately I'm not
looking at using WMI (well, not at the stage of deployment that I require a
screen center)

Thanks again though.

Degs

"Richard T. Edwards" <r.t.e...@attbi.com> wrote in message
news:6Xcx9.56024$bt.8...@rwcrnsc52.ops.asp.att.net...

Joe Earnest

unread,
Nov 3, 2002, 1:35:02 PM11/3/02
to
Derrick,

I'm not sure what you're after. If you just want
raw size from which to determine coordinates,
you can use HTML. Just initiate an
InternetExplorer.Application, get the size, and
never open the window.

Try this:

----start-script----

Set oIEApp= CreateObject("InternetExplorer.Application")

oIEApp.Navigate("about:blank")
Do
WScript.Sleep 50
Loop Until oIEApp.ReadyState=4

With oIEApp.Document.ParentWindow
vWid= .Screen.AvailWidth: vHt= .Screen.AvailHeight
End With

Set oIEApp= Nothing

WScript.Echo vWid, vHt

----end-script----

Regards,
Joe Earnest

"Derrick Guest" <derric...@blueyonder.co.uk> wrote in message
news:uQEU6w0gCHA.3708@tkmsftngp08...

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.410 / Virus Database: 231 - Release Date: 10-31-02


Tom Lavedas

unread,
Nov 3, 2002, 3:17:31 PM11/3/02
to Joe Earnest
Or maybe (using the "Walter Zackery method" ;-) ...

With CreateObject("htmlfile").ParentWindow.Screen
vWid= .AvailWidth: vHt= .AvailHeight
End With

WScript.Echo "Width: ", vWid, "Height: ", vHt

Tom Lavedas
===========

Joe Earnest

unread,
Nov 3, 2002, 5:28:52 PM11/3/02
to
Hi Tom,

Been using some of your posted code for
awhile (always try to give credit when passing
it on). It's good to finally "meet" you in a thread.
So, I'm obviously still learning ...

Just what the devil is the "htmlfile" object? I
can't find a solid mention of it in an MSDN
search. Got a reference?

Regards,
Joe Earnest

"Tom Lavedas" <lav...@pressroom.com> wrote in message
news:3DC5845A...@pressroom.com...

Derrick Guest

unread,
Nov 3, 2002, 6:31:07 PM11/3/02
to
Tom, Joe..

Thanks for that, but no, I'm not looking at an IE instance - the vbscript is
to center a dialog 'form', and all I'm after is the center point of the
screen..

ie...if I was to use VB it would be a case of screen.width and screen.height
etc..etc.....but this isn't working in vbs.

The vbs is being called 'synchronously' from a custom exe that I wrote in VB
as a logon script - simply because the environment that I'm working in is
all NT4 (I'm working towards hopefully upgrading to 2000 so that I can run
the vbs scripts as a logon without the synchronous exe call)

As there will be on-going additions to the logon scripts - various
customisations etc... for the users - I'm "locking out" the running of apps
until the logon process has finished - hence why I'm not making a call to
IE.

I'm then looking at 'wrapping' the scripts in a 'management console' - which
I've already started and which so far is working fine.

Kinda strange that I can't figure out how to get the center co-ords of the
screen without using 'convential' methods - ie wmi etc.. :))

As I said - just a simple thing - but its got me puzzled !!!

degs :)

"Joe Earnest" <joeea...@qwest.net> wrote in message
news:e#ZWbc4gCHA.2460@tkmsftngp10...

Joe Earnest

unread,
Nov 3, 2002, 10:13:51 PM11/3/02
to
Got it. Found Tom's earlier post this month
and an earlier explanatory post by Michael Harris.
Accesses mshtml.dll as the processor directly,
but otherwise behaves as oIEApp.document.
Useful when you want HTML functions but no
window operation.

Joe Earnest

Joe Earnest

unread,
Nov 3, 2002, 10:28:10 PM11/3/02
to
Derrick,

You may be locking out my call to IE,
but are you locking out Tom's method?
His method accesses mshtml.dll as the
processor directly, using the dll code to
provide the information. IE is never
started.

If you can't use Tom's method, can you
get the current screen size setting directly
from the registry? (Running a RegEdit find,
there appear to be a couple of odd places
to grab it on my WinXP, but I don't know
what corresponds to WinNT).

Regards,
Joe Earnest


"Derrick Guest" <derric...@blueyonder.co.uk> wrote in message

news:u9LwiD5gCHA.2592@tkmsftngp12...

Derrick Guest

unread,
Nov 4, 2002, 4:44:14 AM11/4/02
to
Thanks for your help on that Joe,

I'll re-visit the use of mshtml methinks.

Thanks to Tom as well.


degs

"Joe Earnest" <joeea...@qwest.net> wrote in message

news:ujWwq76gCHA.2364@tkmsftngp08...

0 new messages