Solved

Can this function parm be specified to center the clock?

Posted on 2014-04-04
4
305 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 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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
Comment Utility
Works on my PC screen but not on the test vm.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now