Solved

Can this function parm be specified to center the clock?

Posted on 2014-04-04
4
310 Views
Last Modified: 2014-04-04
Hi,
I found a clock that counts in vbscript that I would like use.  Is there any way instead of hard coded, to specify the clock to center in the center of the screen?  Thank you.
clock.vbs
0
Comment
Question by:lapucca
  • 2
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39978811
Give this a try:

' Script starts here
nMinutes = 5
nSeconds = 0
sMessage = "<font color=red size=+1><b>Your computer will restart in 5 minutes.</b></font>"

' Determine screen size (pixels)
Set oWMIService = GetObject("Winmgmts:\\.\root\cimv2")
Set oItems = oWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0)
For Each oItem in oItems
    iScreenWidth = oItem.ScreenWidth
    iScreenHeight = oItem.ScreenHeight
Next 

' Set size and location (centered) of popup window
iHeight = 150
iWidth = 300
iLeft = (iScreenWidth - iWidth) / 2
iTop = (iScreenHeight - iHeight) / 2

' Open a chromeless window with message
with HTABox("lightgrey", iHeight, iWidth, iLeft, iTop)
  .document.title = "IT Maintenance-Keck Medicine of USC"
  .msg.innerHTML = sMessage
  do until .done.value or (nMinutes + nSeconds < 1)
    .msg.innerHTML = sMessage & "<br>" & nMinutes & ":" & Right("0"&nSeconds, 2) _
                   & " remaining<br>"
    wsh.sleep 1000 ' milliseconds
    nSeconds = nSeconds - 1
    if nSeconds < 0 then 
      if nMinutes > 0 then
        nMinutes = nMinutes - 1
        nSeconds = 59
      end if
    end if
  loop
  .done.value = true
  .close
end with
wsh.echo "Your process goes here ..."
' script ends here

' supporting function HTABox
' Author Tom Lavedas, June 2010
Function HTABox(sBgColor, h, w, l, t)
Dim IE, HTA, sCmd, nRnd

  randomize : nRnd = Int(1000000 * rnd)
  sCmd = "mshta.exe ""javascript:{new " _
       & "ActiveXObject(""InternetExplorer.Application"")" _
       & ".PutProperty('" & nRnd & "',window);" _
       & "window.resizeTo(" & w & "," & h & ");" _
       & "window.moveTo(" & l & "," & t & ")}"""

  with CreateObject("WScript.Shell")
    .Run sCmd, 1, False
    do until .AppActivate("javascript:{new ") : WSH.sleep 10 : loop
  end with ' WSHShell

  For Each IE In CreateObject("Shell.Application").windows
    If IsObject(IE.GetProperty(nRnd)) Then
      set HTABox = IE.GetProperty(nRnd)
      IE.Quit
      HTABox.document.title = "HTABox"
      HTABox.document.write _
               "<HTA:Application contextMenu=no border=thin " _
             & "minimizebutton=no maximizebutton=no sysmenu=no />" _
             & "<body scroll=no style='background-color:" _
             & sBgColor & ";font:normal 10pt Arial;" _
             & "border-Style:inset;border-Width:3px'" _
             & "onbeforeunload='vbscript:if not done.value then " _
             & "window.event.cancelBubble=true:" _
             & "window.event.returnValue=false:" _
             & "done.value=true:end if'>" _
             & "<input type=hidden id=done value=false>" _
             & "<center><span id=msg>&nbsp;</span><br>" _
             & "<input type=button id=btn1 value=' OK ' "_
             & "onclick=done.value=true><center></body>"
      HTABox.btn1.focus
      Exit Function
    End If
  Next

' I can't imagine how this line can be reached, but just in case
  MsgBox "HTA window not found."
  wsh.quit

End Function 

Open in new window

~bp
0
 

Author Closing Comment

by:lapucca
ID: 39978850
Works on my PC screen but not on the test vm.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39978864
Try a few of the different variations on this same problem located at the page below.  Sometimes using the display adapter attributes is better, but with multiple screen support etc in Windows you may need to see which WMI object gives you the best results.

If this is too vague let me know, not sure your level of comfort with WMI and VBS.

http://www.activexperts.com/network-monitor/windowsmanagement/scripts/hardware/video/

~bp
0
 

Author Comment

by:lapucca
ID: 39979129
Thank you
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question