Advertisement
omegastripes

countdown_with_reset_quit_buttons_via_mshta.vbs

Mar 30th, 2015
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. If RunCountdown(30 * 60) Then CreateObject("WScript.Shell").Run """%programfiles%\Internet Explorer\iexplore.exe"" ""http://yandex.ru"""
  4.  
  5. Function CreateWindow()
  6.     ' source http://forum.script-coding.com/viewtopic.php?pid=75356#p75356
  7.    Dim sSignature, oShellWnd, oProc
  8.     On Error Resume Next
  9.     sSignature = Left(CreateObject("Scriptlet.TypeLib").GUID, 38)
  10.     Do
  11.         Set oProc = CreateObject("WScript.Shell").Exec("mshta about:""about:<head><script>moveTo(-32000,-32000);document.title=' '</script><hta:application id=app border=thin minimizebutton=no maximizebutton=no scroll=no showintaskbar=yes contextmenu=no selection=no innerborder=no icon=""""/><object id='shell' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shell.putproperty('" & sSignature & "',document.parentWindow);</script></head>""")
  12.         Do
  13.             If oProc.Status > 0 Then Exit Do
  14.             For Each oShellWnd In CreateObject("Shell.Application").Windows
  15.                 Set CreateWindow = oShellWnd.GetProperty(sSignature)
  16.                 If Err.Number = 0 Then Exit Function
  17.                 Err.Clear
  18.             Next
  19.         Loop
  20.     Loop
  21. End Function
  22.  
  23. Function RunCountdown(lSetTime)
  24.     Dim oWnd, sWndType, lInitTime, lRemain
  25.     RunCountdown = False
  26.     On Error Resume Next
  27.     Set oWnd = CreateWindow()
  28.     sWndType = TypeName(oWnd)
  29.     With oWnd
  30.         With .Document
  31.             .Title = "Countdown"
  32.             .Body.Style.Background = "buttonface"
  33.             .Body.Style.Font = "bold 60pt consolas, courier new"
  34.             .Body.InnerHTML = "<center><div id='Output' style='margin: 10px;'>00:00</div><button onclick='Clicked=1;' style='width: 85px; margin: 10px;'>Reset</button><button onclick='Clicked=2;' style='width: 85px; margin: 10px;'>Quit</button></center>"
  35.         End With
  36.         .ResizeTo 350, 230
  37.         .MoveTo 400, 400
  38.         .ExecScript "window.Clicked=0;"
  39.         lInitTime = Timer()
  40.         Do
  41.             If sWndType <> TypeName(oWnd) Then Exit Function
  42.             Select Case .Clicked
  43.             Case 1
  44.                 lInitTime = Timer()
  45.                 .Clicked = 0
  46.             Case 2
  47.                 .Close
  48.                 Exit Function
  49.             End Select
  50.             lRemain = 86400 + lSetTime + lInitTime - Timer()
  51.             Do While lRemain >= 86400
  52.                 lRemain = lRemain - 86400
  53.             Loop
  54.             If lRemain < 600 Then
  55.                 .Output.InnerHTML = "0" & (lRemain \ 60) & ":" & Right("0" & lRemain Mod 60, 2)
  56.             Else
  57.                 .Output.InnerHTML = (lRemain \ 60) & ":" & Right("0" & lRemain Mod 60, 2)
  58.             End If
  59.             WScript.Sleep 40
  60.         Loop While lRemain > 0
  61.         .Close
  62.     End With
  63.     RunCountdown = True
  64. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement