Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can this function parm be specified to center the clock?

Posted on 2014-04-04
4
Medium Priority
?
326 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 59

Accepted Solution

by:
Bill Prew earned 2000 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 59

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

877 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