Can this function parm be specified to center the clock?

Posted on 2014-04-04
Last Modified: 2014-04-04
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.
Question by:lapucca
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 56

Accepted Solution

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

' 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
  .done.value = true
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)
      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>"
      Exit Function
    End If

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

End Function 

Open in new window


Author Closing Comment

ID: 39978850
Works on my PC screen but not on the test vm.
LVL 56

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.


Author Comment

ID: 39979129
Thank you

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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