Solved

Can this function parm be specified to center the clock?

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

810 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