2015-04-02 127 views
1

我需要有一個計時器出現在消息框中,編碼爲vbs。消息框需要位於屏幕的左下角,就在開始菜單的上方。它需要不能退出,這意味着它不能在任務欄上列出(希望),並且沒有最小化/退出按鈕。它需要保持在所有其他窗口之上。它也需要從20分鐘開始,以秒爲單位倒計時。我希望有人能幫助我 - 這是一個計算機實驗室。如何使VBScript計時器

感謝, 馬修

+2

能否請你告訴你的代碼?你嘗試了什麼? – abarisone 2015-04-02 06:26:01

+0

你可以用[HTA](http://blogs.msdn.com/b/noahc/archive/2007/03/25/html-applications-htas.aspx)做到這一點,雖然可能不是「留在頂部「要求 – 2015-04-02 14:11:54

回答

0

嘗試類似的東西:

Option Explicit 
Dim Title,ws,nMinutes,nSeconds,sMessage 
Title = "Counting Down to Shutdown" 
Set ws = CreateObject("wscript.Shell") 
nMinutes = 20 
nSeconds = 0 
sMessage = "<font color=Red size=2><b>Counting Down to Shutdown" 
'Open a chromeless window with message 
with HTABox("lightBlue",100,250,0,630) 
    .document.title = "Counting Down Notification to Shutdown" 
    .msg.innerHTML = sMessage 
    do until .done.value or (nMinutes + nSeconds < 1) 
     .msg.innerHTML = sMessage & "<br>" & nMinutes & ":" & Right("0"&nSeconds, 2) _ 
     & " remaining</b></font><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 
ws.Popup "TIME IS OVER !","5",Title,0+48 'Afficher un Popup durant 5 secondes puis on quitte le script 
'Command="cmd /c Shutdown.exe -s -t 30 -c " & DblQuote("Sauvegarder votre Travail car l'ordinateur va rebooter dans 30 secondes") 
'Executer = WS.Run(Command,0,False) 
'***************************************************************** 
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 SHOWINTASKBAR=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 
     MsgBox "HTA window not found." 
     wsh.quit 
End Function 
'***************************************************************** 
+0

謝謝!這工作完美。我的系統管理員喜歡它。我已經編寫了一個腳本,以便在計算機重新啓動時間到。我希望在所有學校實驗室的50臺PC上實施並不需要太長時間! – 2015-04-12 22:46:05

+0

所以,如果你發現它是有用的,那麼,你應該投票並接受它! – Hackoo 2015-04-12 23:07:26

+0

等待 - 可以將「註銷」按鈕添加到此? – 2015-04-12 23:17:49